Traversing an array in program processing is a common operation, but we need to know the length of each dimension of the array, except for one-dimensional arrays, and the length of the multidimensional array, as described in the following example.
One-dimensional:
int [] Array ={1 2 3 4 5};
Size = Array.Length ();
Two-dimensional arrays:
Java does not actually have multidimensional arrays, only one-dimensional arrays. Multidimensional arrays can be understood as "arrays of arrays"; For example, a two-dimensional array is actually a one-dimensional array, and each element in the array is a one-dimensional array. Thus the length of the row is obtained.
int [] [] array = {{1, 2,3},{4,5,6},{7,8,9}};
int rows = Array.Length;
int columns = Array[0].length;
This feature can be generalized to a multidimensional array:
Multidimensional Arrays:
int []1 []2 ... []n array = {};
1-d Array.Length;
2-d Array.length[0];
.
N-d array[0]1[0]2 ... [0]n-1;
The length of each dimension is obtained according to the above, which makes it easy to iterate through all the elements.
How to get the length of a multidimensional array in Java