0

I want to clarify something. This is my code:

List<GameObject>[] dynamicCells;                      //1
List<GameObject>[] staticCells;                       //2

dynamicCells = new List[numCells];                    //3
staticCells = new List[numCells];                     //4

for (int i = 0; i < numCells; i++) {
    dynamicCells[i] = new ArrayList<GameObject>(10);  //5
    staticCells[i] = new ArrayList<GameObject>(10);   //6
}

On the first and second step I create an "empty" array of GameObject list reference. On the third and fourth step I allocate memory for an array of List which I return its address reference. On the 5, 6 step I create a new ArrayList reference of type GameObject which I assign on my List.

So in the end I am left with an array Of list references that each one hold an ArrayList of game objects. Is this right ? Is there any better way to explain this ?

1
  • 1
    That's correct. Each variable is an array of List objects. Commented Oct 19, 2014 at 14:09

1 Answer 1

2

1 and 2 are variable declarations, nothing is created there.

3 and 4 create arrays and assign them to the variables (in the process allocating memory, but only for the arrays of object references).

5 and 6 create new empty generic ArrayLists that are assigned to a position in the array.

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

1 Comment

Thanks for your answer, as i said i was pretty confused but now i am sure :)

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.