2d array initialization in java code example
Example 1: java two dimensional arrays
int[][] multiples = new int[4][2];
and 2 columns
String[][] cities = new String[3][3];
and 3 columns
Example 2: 2d array java
int[][]arr= new int [filas][columnas];
arr.length=filas;
int[][] a = {
{1, 2, 3},
{4, 5, 6, 9},
{7},
};
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 3: How to create a 2d array in java
int[][] arr = new int[m][n];
Example 4: Java 2d array initialization
class TwoDimensionalArray {
public static void main(String[] args) {
String[][] salutation = {
{"Mr. ", "Mrs. ", "Ms. "},
{"Kumar"}
};
System.out.println(salutation[0][0] + salutation[1][0]);
System.out.println(salutation[0][1] + salutation[1][0]);
}
}
The output from this program is:
Mr. Kumar
Mrs. Kumar
Example 5: how to initialize one dimensional array in java
int[] a;
int b[];
int[] c;