Finding length of all arrays multidimensional array, Java

HedonicHedgehog picture HedonicHedgehog · Sep 19, 2012 · Viewed 21.9k times · Source

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

arshajii picture arshajii · Sep 19, 2012

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