Finding length of all arrays multidimensional array, Java
Try using array[0].length
, this will give the dimension you're looking for (since your array is not jagged).
boolean[][] array = new boolean[3][5];
Creates an array of three arrays (5 boolean
s each). In Java multidimensional arrays are just arrays of arrays:
array.length
gives you the length of the "outer" array (3 in this case).
array[0].length
gives you the length of the first "inner" array (5 in this case).
array[1].length
and
array[2].length
will also give you 5, since in this case, all three "inner" arrays, array[0]
, array[1]
, and array[2]
are all the same length.