Reputation: 3370
I need some help with how this array works:
String[][] stringz = new String[5][4];
System.out.println(stringz[x][y]);
When I try to output using stringz[1][3]
, I have the null data output.
when I try to output using stringz[0][3]
, I also have the null data output.
I know that in arrays index begins by 0.
So I also want to output the data in [0][4]
But java compilation shows me an error? Why? If i have 5 data boxes (5-1) = index #4 should be the last?
Upvotes: 0
Views: 82
Reputation: 776
Your two dimensional array's indexes are below.
0,0__0,1__0,2__0,3
1,0__1,1__1,2__1,3
2,0__2,1__2,2__2,3
3,0__3,1__3,2__3,3
4,0__4,1__4,2__4,3
So, you don't have fourth index in your second dimension.
Upvotes: 3