What is the correct way to declare a multidimensional array and assign values to it?
This is what I have:
int x = 5;
int y = 5;
String[][] myStringA
You can also use the following construct:
String[][] myStringArray = new String [][] { { "X0", "Y0"},
{ "X1", "Y1"},
{ "X2", "Y2"},
{ "X3", "Y3"},
{ "X4", "Y4"} };
I'll add that if you want to read the dimensions, you can do this:
int[][][] a = new int[4][3][2];
System.out.println(a.length); // 4
System.out.println(a[0].length); // 3
System.out.println(a[0][0].length); //2
You can also have jagged arrays, where different rows have different lengths, so a[0].length != a[1].length
.