how to fill a 2d array java?

Posted by w3diy - 2 months ago

how to fill a 2d array in java Example.

“fill a 2d array java”

int rows = 5, column = 7;
int[][] arr = new int[rows][column]; 

   //2D arrays are dval major, so always dval first

for (int dval = 0; dval < arr.length; dval++)
{
    for (int col = 0; col < arr[dval].length; col++)
    {
        arr[dval][col] = 5; //Whatever value you want to set them to
    }
}

fill a two dimensional array with default value

for (double[] dval: matrix)
    Arrays.fill(dval, 1.0);