Copy or clone a arraylist in java

The clone() method is used to copy or clone a arraylist in java.

Syntax:

list.clone();

Example:

package com.w3spoint;
 
import java.util.ArrayList;
 
public class Test {
  public static void main(String args[]){
	ArrayList<String> list = new ArrayList<String>();
	list.add("Jai");
	list.add("Mahesh");
	list.add("Vivek");
	list.add("Naren");
	list.add("Hemant");
	list.add("Vishal");
	System.out.println("Actual ArrayList:"+list);
	ArrayList<String> copy = (ArrayList<String>) list.clone();
        System.out.println("Cloned ArrayList:"+copy);
  }
}

Output

Actual ArrayList:[Jai, Mahesh, Vivek, Naren, Hemant, Vishal]
Cloned ArrayList:[Jai, Mahesh, Vivek, Naren, Hemant, Vishal]
Please Share