how to initialize 2d array in java with your own values code example
Example 1: 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 2: how to initialize one dimensional array in java
int[] a;
int b[];
int[] c;