How to append to array of arrays instance variable?

1419 views java

I have an instance variable inside a class that looks like

private GridLocation [][] world;

I'm not sure how you add values to a pair of angle brackets like that. I just know that the two values represent the coordinates of a square in a grid. How would you add the square (1,2) for example? According to my book, you assign values inside the constructor with = name;

I'm very unsure what to do in this case though

answered question

world[1][2] = yourGridLocation;

1 Answer


as @GBlodgett already answered the question. It is a "multidimensional" Array or array of arrays. It works like a single array where you can choose between different arrays.

world[1][2] = yourGridLocation;

you should also have a look how to initialise it. Here is a link to a similiar question.

In Java, a two-dimensional array is represented by an array of arrays in which every sub-array is of the same length: quote enter image description here

posted this

Have an answer?


Please login first before posting an answer.