| 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?
|
boolean b = true;<br />System.out.println ("I believe in Java.<br />Java will make my dream come " + b);
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8441
|
|
Originally posted by adam lui: how i could possily prevent this from happening?
Try List tempList = new ArrayList(list);
|
[Donate a pint, save a life!] [How to ask questions] [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.
|
 |
 |
|
|
subject: Arraylist
|
|
|