I have an object anObject with two private member variables:
public class anObject {
private String name;
private ArrayList<String> myList = new ArrayList<String>();
}
I have a constructor:
public anObject() {
name = "";
}
I have my copy constructors:
public anObject(anObject copy) {
this();
newObject(copy);
}
public void newObject(anObject copyTwo) {
name = copyTwo.name;
// How to deep copy an ArrayList?
}
But how can I "deep copy" all the elements of my ArrayList in copyTwo, to my this.myList?
I have looked at the other questions on SO but their ArrayLists all contain objects whereas mine just contains Strings. Thanks for any help!
Stringis not an object?ArrayListhas a copy constructor, you can use that.