C graphics C graphics - 3 months ago 22
Java Question

Shortest way to cast a 2d int array into 2d double

I have a method which only gets

double[][]
to which I would like to pass
int[][]
, is there a short way of doing this in java, something as simple as:

int [][] iArray = {
{ 1, 2, },
{ 5, 6, }
};
double [][] dArray = (double[][]) iArray ; ???

Answer

Unfortunately the only way to cast your array is to iterate through each element and cast them one by one while re-inserting in your new double[][] array.

There is no shortcut.