Copy contents of an int array to a double array in Java?

前端 未结 4 1521
无人及你
无人及你 2021-01-04 20:35

I\'m trying to copy the contents of my int array into an array of type double. Do I have to cast them first?

I successfully copied an array of type int to another a

4条回答
  •  Happy的楠姐
    2021-01-04 21:09

    Worth mentioning that in this day and age, Java 8 offers an elegant one-liner to do this without the need to use third-party libraries:

    int[] ints = {23, 31, 11, 9};
    double[] doubles = Arrays.stream(ints).asDoubleStream().toArray();
    

提交回复
热议问题