HedonicHedgehog HedonicHedgehog - 21 days ago 4
Java Question

Finding length of all arrays multidimensional array, Java

I would like to use a multidimensional array to store a grid of data. However, I have not found a simple way to find the length of the 2nd part of the array. For example:

boolean[][] array = new boolean[3][5];
System.out.println(array.length);


will only output 3.

Is there another simple command to find the length of the second array? (i.e. output 5 in the same manner)

Answer

Try using array[0].length, this will give the dimension you're looking for (since your array is not jagged).

Comments