• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is the ArrayList Object not Created Befor assigning values from ArrayList loc

 
Varuna Seneviratna
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The above Class in the method setLocationCells() assigns the string value loc without creating a ArrayList object or using the add method, In this scenario what happens?Is this like declaring a array variable and assigning values?


Varuna
[ October 02, 2008: Message edited by: Varuna Seneviratna ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use a more informative title for your threads than "what is the difference."

No, it is nothing like creating an array and assigning a member at all. You are not assigning the String value loc because loc isn't a String.

The field loc is an ArrayList<String> so you have to create an ArrayList<String> reference somewhere else and put that reference to an ArrayList<String> into that set method and into the loc reference. The ArrayList<String> will contain as many or as few Strings as were put into it "somewhere else," but you could of course change that after it is passed.
 
Varuna Seneviratna
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean that a ArrayList<String> object should be created somewhere else, assign values or strings to it, pass it to setLocations method. this will result in locationCells pointing to a ArrayList String type Object?


Varuna
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Varuna Seneviratna
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Richie

Varuna
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic