tags:

views:

108

answers:

3

If I have a 2D array arr[rows][columns], how could I use arr.length to find size for rows and columns individually?

+2  A: 
arr.length 

will be the number of rows

arr[x].length

will be the number of columns in row x.

sje397
+4  A: 

You can find the number of rows as:

arr.length

In Java all the rows need not have same number of elements. You can find the number of elements in the row i as:

arr[i].length
codaddict
+3  A: 
Rows - arr.length
Columns -arr[rowNumber].length //Each row can have different number of elements
Emil