Gurus , I am stuck here ,I've done arrays in my high school but finding this array hard to understand .. All my confusion started with the below e.g from Java tutorial.
class MultiDimArrayDemo {
public static void main(String[] args) {
String[][] names = {
{"Mr. ", "Mrs. ", "Ms. "},
{"Smith", "Jones"}
};
// Mr. Smith
System.out.println(names[0][0] + names[1][0]);
// Ms. Jones
System.out.println(names[0][2] + names[1][1]);
}
}
========================================
My understanding ..this should be creating a matrix of 3x2
row x column
Matrix:
00 01
10 11
20 21
so I think,
00 = Mr.Smith
01 = Mr.Jones
10 = Mrs.Smith
11 = Mrs.Jones
20 = Ms.Smith
21 = Ms.Jones
So this should .." System.out.println(names[0][0] + names[1][0]);" print Mr.Smith Mrs.Smith
and this should .. System.out.println(names[0][2] + names[1][1]); .. [0][2] is not in matrix and [1][1] is Mrs>Jones
So why the output is different .. can some one plz explain where I am going wrong