I am watching a tutorial on 2d arrays and I can't seem to understand where the values for states.length and states[i].length are coming from. How does it know the outer loop deals with the size 3 array and the inner is the size 2 array?
public class Test3 {
public static void main(String[] args) {
String [][] states = new String[3][2];
states[0][0] = "California";
states[0][1] = "Sacremento";
states[1][0] = "Oregon";
states[1][1] = "Salem";
states[2][0] = "Washington";
states[2][1] = "Olympia";
for (int i = 0; i < states.length; i++) {
StringBuilder sb = new StringBuilder();
for (int j = 0; j < states[i].length; j++) {
sb.append(states[i][j]);
}
System.out.println(sb);
}
}
}