Java Arrays.fill() Java Arrays.fill() arrays arrays

Java Arrays.fill()


Here's a suggestion using a for-each:

for (int[] row : array)    Arrays.fill(row, 0);

You can verify that it works by doing

System.out.println(Arrays.deepToString(array));

A side note: Since you're creating the array, right before the fill, the fill is actually not needed (as long as you really want zeros in it). Java initializes all array-elements to their corresponding default values, and for int it is 0 :-)


Try this:

for(int i = 0; i < array.length; i++) {    Arrays.fill(array[i], 0);}

I haven't tested it but I think it should work.


Since array is really an array of arrays, perhaps you can try looping over each row and doing fill for each one individually.