6

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

3 Answers 3

9
arr.length 

will be the number of rows

arr[x].length

will be the number of columns in row x.

Sign up to request clarification or add additional context in comments.

Comments

6

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.