javacodex.com
Java Examples
Java Examples
memu home questions

Clone An ArrayList

Here is an example for creating a duplicate object of an ArrayList instance.

Source: (CloneArrayList.java)

import java.util.ArrayList;
 
public class CloneArrayList { 
   public static void main(String[] args) { 
      ArrayList list = new ArrayList();
      list.add("John");
      list.add("Ringo");
      list.add("George");
      list.add("Paul");
      System.out.println("ArrayList : "+ list);
      ArrayList<String> clone = (ArrayList<String>) list.clone();
      System.out.println("ArrayList Clone: "+ clone);
   } 
}
 

Output:

# java CloneArrayList 
ArrayList : [John, Ringo, George, Paul]
ArrayList Clone: [John, Ringo, George, Paul]

Contact: javacodex@yahoo.com