Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

casting

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 ; ???
like image 592
C graphics Avatar asked Nov 29 '22 15:11

C graphics


1 Answers

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.

like image 63
dee-see Avatar answered Dec 05 '22 01:12

dee-see