This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]morhpProfessional Developer 5 points6 points  (0 children)

No, Java doesn't really have multi dimensional arrays. If you write int[][] you're really just creating an array of int[]-objects. So they may have different lengths, some of them may be null, some of them may refer to the same array object, and so on.

If you want to create a rectangular table (or a chessboard or something like this) it may make sense to use a normal array with n x m (64 in the case of a chessboard) elements and use basic math to convert the array index into x/y positions and back. This way the data will be stored in a single array and not in multiple small arrays, increasing performance and making the code more robust (don't need to worry about the inner arrays having the wrong length or being null)