How to get rows and columns count of a 2D array in Java?

Well you probably want array_name.length for getting the count of the rows and array_name[0].length for the columns. That is, if you defined your array like so:

T[][] array_name = new T[row][col];
array_name.length // row
array_name[0].length // col

Leave a Comment