How do I copy ArrayList in Java 1.5?
ArrayList<Dog> dogs = getDogs();
ArrayList<Dog> clonedList = ...Copy each item of dogs...
For example, if I want to copy dogs to the clonedList like this, how can I do it?
java collections clone deep-copy
public static List<Dog> cloneList(List<Dog> list) {
List<Dog> clone = new ArrayList<Dog>(list.size());
for(Dog item: list) clone.add(item.clone());
return clone;
}
You can do a repeat statement like this and add it to the closed list one by one.
© 2024 OneMinuteCode. All rights reserved.