Java 8 1- int double:
double[] singleDimensionDoubleArray =
Arrays.stream(singleDimensionIntArray).asDoubleStream().toArray()
, , , , :
int[][] iArray = {
{1, 2,},
{5, 6,}
};
double[][] dArray = new double[iArray.length][];
for (int row = 0; row < iArray.length; row++) {
dArray[row] = Arrays.stream(iArray[row]).asDoubleStream().toArray();
}
I was just about to publish this answer, but I thought that I would publish some indicators about how much faster this was a naive cycle over each element. Turns out it was about 10x slower ! I tested it with an array of zeros at 10000x1000. I suppose this is creating an additional object that causes a slowdown.
If someone else cannot prove the opposite, I think the simplest solution is actually the fastest:
for (int row = 0; row < iArray.length; row++) {
for (int column = 0; column < iArray[0].length; column++) {
dArray[row][column] = (double) iArray[row][column];
}
}
source
share