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

前端 未结 4 1522
无人及你
无人及你 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条回答
  •  借酒劲吻你
    2021-01-04 21:27

    From System.arraycopy JavaDoc

    [...] Otherwise, if any of the following is true, an ArrayStoreException is thrown and the destination is not modified:

    *...

    *...

    *The src argument and dest argument refer to arrays whose component types are different primitive types. [...]

    Since int and double are different primitive types you will have to manually iterate through one array and copy its content to another one.

提交回复
热议问题