clone()
for ArrayLists
should be avoided because even if it creates a new List
instance, it holds the same elements. So an element changed on the first List
will also be changed on the second one. Two different objects holding the same references.
The code below will create a new instance with new elements.
ArrayList<Object> realClone = new ArrayList<Object>();
for(Object o : originalList)
realClone.add(o.clone());