how does java handle 2d arrays code example

Example 1: accessing 2d array in java

(m x n matrix) - (2 x 3 matrix)  
m	n ------------------ >
|	a[0][0] a[0][1] a[0][2]
v	a[1][0] a[1][1] a[0][2]

Example 2: 2d array java

//Length
int[][]arr= new int [filas][columnas];
arr.length=filas;

        int[][] a = {
            {1, 2, 3}, 
            {4, 5, 6, 9}, 
            {7}, 
        };
      
        // calculate the length of each row
        System.out.println("Length of row 1: " + a[0].length);
        System.out.println("Length of row 2: " + a[1].length);
        System.out.println("Length of row 3: " + a[2].length);
    }

Tags:

Cpp Example