0

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

this.name = name;

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

1 Answers1

2

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.

 GridLocation [][] world = new GridLocation[x][y];//x, and y are the size of your array


 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

Khan
  • 1,418
  • 1
  • 25
  • 49