Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2D Array Question Java

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

like image 929
Snowman Avatar asked Oct 04 '10 04:10

Snowman


3 Answers

arr.length 

will be the number of rows

arr[x].length

will be the number of columns in row x.

like image 89
sje397 Avatar answered Oct 16 '22 00:10

sje397


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
like image 6
codaddict Avatar answered Oct 15 '22 23:10

codaddict


Rows - arr.length
Columns -arr[rowNumber].length //Each row can have different number of elements
like image 4
Emil Avatar answered Oct 16 '22 01:10

Emil