Given an Arrayl.ist that contains a list of Employee object references, describe two
ways in which you could write code to make a copy of that ArrayL ist. (Hint: one way
would be a shallow copy). Use code examples to illustrate your answer. Discuss the
implications of each way you have given above with regard to variable references
within the Arraylist and Employee objects.
Would this do?
public class Main {//SHALLOW COPY
public static void main(String args[]) {
ArrayList<String> al = new ArrayList<String>();
al.add("C");
al.add("A");
al.add("E");
al.add("java2s.com");
al.add("D");
al.add("F");
al.add(1, "java2s.com");
System.out.println(al);
Object list = al.clone();
System.out.println(list);
}
and how would a deep copy look like??
I would appreciate any help :-)