Clone ArrayList In Java Example
Chapter:
Collections
Last Updated:
16-04-2016 03:14:33 UTC
Program:
/* ............... START ............... */
import java.util.ArrayList;
public class JavaCloneArrayList {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add("One");
arrayList.add("Two");
arrayList.add("Three");
arrayList.add("Four");
System.out.println("ArrayList : " + arrayList);
ArrayList<String> clone = (ArrayList<String>) arrayList.clone();
System.out.println("ArrayList Clone: " + clone);
}
}
/* ............... END ............... */
Output
ArrayList : [One, Two, Three, Four]
ArrayList Clone: [One, Two, Three, Four]
Notes:
-
The java.util.ArrayList.clone() returns a shallow copy of this ArrayList instance
Tags
Collection, Clone ArrayList, Java