See Arun here
String[] sa[]=new String[2][];
means now you have
sa[0]
and
sa[1]
and
sa[0]=new String[]{"A","B","C","D"};
means
sa[0]=|"A"|"B"|"C"|"D"|
0 1 2 3
and
sa[1]=null;
means
sa[0][0]="A"
sa[0][1]="B"
sa[0][2]="C"
sa[0][3]="D"
so
sa[1][0], sa[1][1] cannot be called as sa[1]=null. If you try to call
sa[1][0], you are calling null[0] that is NullPointerException.
So now
for(String[] s:sa){
/*
first time sa[0] in sa[2][]
second time sa[1] in sa[2][]
*/
System.out.print(s[1]+", ");
/*first time it will come for sa[0] and will call sa[0][1] it is ok
in second loop it will come for sa[1] and will call sa[1][1] means null[1] so You are calling [] operator on null that is NullPointerException.*/
System.out.print(s[2]+", ");
}
[ December 16, 2008: Message edited by: punit.singh ]