0

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?

3
  • 2
    The largest indices you can use, given your declaration of stringz, is [4][3]. You are violating this constraint by using a number greater than 3 for the 2nd index. Commented Mar 16, 2017 at 17:47
  • Thank u bro, i just confused with 1array type and multidimensional type. Commented Mar 16, 2017 at 17:51
  • 1
    To clarify, if you have an array initialized with new String [m][n], the largest indices in this array would be array[m-1][n-1]. Commented Mar 16, 2017 at 17:53

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.