• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with ArrayList  RSS feed

 
Broderick Calpe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I'm wondering what this line does:


What will hold exactly?

Later on this is done:



Shouldn't al.size() always just be 1 or am I missing something here?

Please help
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the first line creates is essentially a 2 D array. The way Java allows you to create one is an array of other arrays. So grid is an array of 100 arrays, and each of these arrays contains an array of 50 ArrayLists.

a1 will be a reference to the ArrayList stored in row c and column d. That is, c indicates which of the arrays out of the 100 to look for, and d indicates which of the ArrayLists in that array to use.

It's size will change if you add elements to it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!