| Author |
Problems with addAll() from ArrayList - same reference...
|
Luciano Assis
Greenhorn
Joined: Apr 30, 2008
Posts: 16
|
|
Hello folks, I want to clone an arrayList, but with different references (2 objects). I tried to create a new arraylist and use de method addAll() passing the list, but it still continue with the same reference, if i modify some propertie of the new arrayList, the same propertie from the original list is modified too.. How can i clone an arraylist with 2 distinct objects?
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
See the Cloning objects topic from Eckel's Thinking in Java. This section specifically addresses cloning an ArrayList and talks about "shallow" vs. "deep" copies (A deep copy with ArrayList).
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
 |
|
|
subject: Problems with addAll() from ArrayList - same reference...
|
|
|