Cloning the objects before adding them. For example, instead of newList.addAll(oldList);
for(Person p : oldList) {
newList.add(p.clone());
}
Assuming clone
is correctly overriden inPerson
.
More Related Contents:
- Removing duplicates from arraylist using set
- How to check two array list are same content in same position
- Logical disjunction of a list of booleans represented by integers [closed]
- ArrayList remove methods [closed]
- ArrayList, Loop and requisite if can not work that i want – Java 11
- How do I remove repeated elements from ArrayList?
- Sorting an ArrayList of objects using a custom sorting order
- How to convert an ArrayList containing Integers to primitive int array?
- How does a ArrayList’s contains() method evaluate objects?
- Common elements in two lists
- Concurrent Modification Exception : adding to an ArrayList
- How do I make my ArrayList Thread-Safe? Another approach to problem in Java?
- Java: how can I split an ArrayList in multiple small ArrayLists?
- What is the difference between List and ArrayList? [duplicate]
- ArrayList initial capacity and IndexOutOfBoundsException [duplicate]
- How to zip two Java Lists
- How to convert a String into an ArrayList?
- How do I declare a 2D String arraylist?
- ArrayList filter [duplicate]
- Searching in a ArrayList with custom objects for certain strings
- java.util.Vector – alternatives
- ArrayList or List declaration in Java
- Arrays.asList() of an array
- How does ArrayList work?
- How to change value of ArrayList element in java
- In Java, can you modify a List while iterating through it?
- How to merge two ArrayLists without duplicates? [duplicate]
- Why do I need to synchronize a list returned by Collections.synchronizedList
- Add ArrayList to another ArrayList in java
- Assigning an array to an ArrayList in Java