Snowman
Snowman

Reputation: 32091

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?

Upvotes: 6

Views: 4428

Answers (3)

Emil
Emil

Reputation: 13799

Rows - arr.length
Columns -arr[rowNumber].length //Each row can have different number of elements

Upvotes: 4

codaddict
codaddict

Reputation: 455380

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

Upvotes: 6

sje397
sje397

Reputation: 41862

arr.length 

will be the number of rows

arr[x].length

will be the number of columns in row x.

Upvotes: 9

Related Questions