Java 2D array question

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

+6
java arrays multidimensional-array
source share
4 answers
 arr.length 

there will be a number of lines

 arr[x].length 

will be the number of columns in row x .

+9
source share

You can find the number of lines as:

 arr.length 

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

 arr[i].length 
+6
source share
 Rows - arr.length Columns -arr[rowNumber].length //Each row can have different number of elements 
+4
source share

arr.length This will give you the number of rows in your 2D array

arr[i].length This will give you the number of colonies of a particular line ....

Therefore, arr[i].length reduces the time it takes to use it in a loop ...

This means that if line 0 has 3 values ​​and line 1 has 2 values ​​...

-one
source share

All Articles