2d array in java initialization code example

Example 1: 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);
    }

Example 2: two dimensional array in java example program

String[][][] data = new String[3][4][2];

Example 3: How to create a 2d array in java

int[][] arr = new int[m][n];

Example 4: how to initialize one dimensional array in java

int[] a; // valid declaration
int b[]; // valid declaration 
int[] c; // valid declaration

Tags:

Java Example