Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Arraylist  RSS feed

 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ok...i add value at - list.add(343); -
and "itTemp" was added value 343 to, too, but why and how to avoid?
how i could possily prevent this from happening?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by adam lui:
how i could possily prevent this from happening?


Try List tempList = new ArrayList(list);
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


At this point, tempList and list both reference the exact same ArrayList object. You don't actually have two lists, but two references to one list. If you want something added to one list but not another, you first need to have two lists to work with.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!