Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with addAll() from ArrayList - same reference...  RSS feed

 
Luciano Assis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!