This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arraylist" Watch "Arraylist" New topic
Author

Arraylist

adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186


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
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Originally posted by adam lui:
how i could possily prevent this from happening?


Try List tempList = new ArrayList(list);


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271


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.


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arraylist