#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    ArrayList problems


    Hi!

    I'm wondering what this line does:
    Code:
    ArrayList[][] grid = new ArrayList[100][50];
    
    water.grid[h][v].push_back(&i);
    
    // c and d are calculated values.
    ArrayList al = this.grid[c][d];
    What will
    Code:
    al
    hold exactly?

    Later on this is done:

    Code:
    int n = al.size();
    for (int q = 0; q < n; q++) {
       int j = ((Integer)al.get(q)).intValue();
       
       ........
    Shouldn't al.size() always just be 1 or am I missing something here?

    Please help
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    An array of objects has slots to hold references to objects. Initially the slots have null values. The code needs to assign values to the slots.
    To get one of the objects held in a slot use array notation:
    anObj = theArray[oneIndex][secondIndex]

    The contents of the object (for example its size) has nothing to do with it having been stored in a slot of an array.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by NormR
    An array of objects has slots to hold references to objects. Initially the slots have null values. The code needs to assign values to the slots.
    To get one of the objects held in a slot use array notation:
    anObj = theArray[oneIndex][secondIndex]

    The contents of the object (for example its size) has nothing to do with it having been stored in a slot of an array.

    I haven't posted all the code here so there are parts left out.
    What I'm trying to find out is what this line actually does.

    Code:
    ArrayList al = this.grid[c][d]
    Does it copy the content in the grid[c][d] into ArrayList al ?
    Or does it copy the offset of the grid into al ?
    Meaning that you have a part of the grid list in al.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    It copies the contents of the grid[c][d] slot into the variable al.

IMN logo majestic logo threadwatch logo seochat tools logo