I have a variable of type List<RelationHeader>.
Now I want to copy all the elements in this list to a new list, but I want to actually copy all the members by value (clone them). Is there a quick command to do this, or do I need to iterate over the list and copy them one at a time?
Asked
Active
Viewed 1,054 times
0
Amir Rachum
- 72,441
- 71
- 163
- 242
-
1See: http://stackoverflow.com/questions/715650/java-how-to-clone-arraylist-but-also-clone-its-items – Jon Apr 25 '10 at 19:33
1 Answers
2
You'll have to do this manually. There's no generally accepted way of deep-copying objects in Java (clone() is not really used for this - see this Joshua Bloch article) and you'll have to determine yourself how deep you want to copy those objects.
Brian Agnew
- 261,477
- 36
- 323
- 432