I studied Java is pass object reference by value, and in order to make a local copy of an object, I can either do clone() or copy-constructor. I also looked at deep/shallow copy as well as several post on stackoverflow.
Now I am looking at example:
List<String> list = new ArrayList<String>();
String one = "one"
list.add(one);
Few articles I read only mentions that ArrayList implements cloneable but does not really say how to make a local copy of "list" if type is List not ArrayList which does not implements cloneable.
I can call clone() if "list" is type of ArrayList.
ArrayList<String> list = new ArrayList<String();
list.clone();
But if type is List, I cannot.
Should I just use copy constructor like below to make local copy? What is the best way to make a copy of "list"?
List<String> tmpList = new ArrayList<String>(list);