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
  • 3
    world[1][2] = yourGridLocation; Commented Sep 15, 2018 at 16:49

1 Answer 1

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

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.