arraylist clone 28 29 method in java

Solutions on MaxInterview for arraylist clone 28 29 method in java by the best coders in the world

showing results for - "arraylist clone 28 29 method in java"
Giovanni
06 May 2018
1import java.util.ArrayList;
2public class ArrayListCloneMethodExample
3{
4   public static void main(String[] args)
5   {
6      ArrayList<String> al = new ArrayList<String>();
7      al.add("violet");
8      al.add("indigo");
9      al.add("blue");
10      al.add("green");
11      al.add("yellow");
12      System.out.println("ArrayList before using clone() method: " + al);
13      // create another ArrayList and copy
14      ArrayList<String> arrClone = new ArrayList<String>();
15      arrClone = (ArrayList)al.clone();
16      System.out.println("ArrayList after using clone() method: " + arrClone);
17   }
18}