I'am trying to create simple 2 dimensional array of double.
Using for loop it's not a big deal to make it like:
static public double[][] genMatrix(int n) {
double mat[][]=new double[n][n];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
mat[i][j]=generateDouble();
return mat;
}
I'd like to do it smoother with a lambda expression and forEach but I'm getting an array full of zeros. Why?
private static double[][] genSquareMatrix(int matrixDimension) {
double matrix[][] = new double[matrixDimension][matrixDimension];
Arrays.stream(matrix).forEach(x->Arrays.stream(x).forEach(y-> y = generateDouble()));
return matrix;
}
By the way, when I use a lambda to print that array there is no problem.
ybygenerateDouble.