How to clone an ArrayList to another ArrayList in Java? Last Updated : 19 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The clone() method of the ArrayList class is used to clone an ArrayList to another ArrayList in Java as it returns a shallow copy of its caller ArrayList. Syntax: public Object clone(); Return Value: This function returns a copy of the instance of Object. Below program illustrate the Java.util.ArrayList.clone() method: Example: Java // Java program to clone an ArrayList to another ArrayList import java.util.ArrayList; public class GFG { public static void main(String a[]) { // create ArrayList ArrayList<String> ArrList1 = new ArrayList<String>(); // Insert elements in ArrayList ArrList1.add("Mukul"); ArrList1.add("Rahul"); ArrList1.add("Suraj"); ArrList1.add("Mayank"); // print ArrayList1 System.out.println("Original ArrayList = " + ArrList1); // clone ArrayList ArrayList ArrList2 = (ArrayList)ArrList1.clone(); // print ArrayList2 System.out.println("Clone ArrayList2 = " + ArrList2); } } OutputOriginal ArrayList = [Mukul, Rahul, Suraj, Mayank] Clone ArrayList2 = [Mukul, Rahul, Suraj, Mayank] Time complexity: O(N) where N is the size of ArrayList Auxiliary Space: O(N) Example 2: Java // Java code to illustrate clone() method import java.io.*; import java.util.*; public class ArrayListDemo { public static void main(String args[]) { // Creating an empty ArrayList ArrayList<Integer> list = new ArrayList<Integer>(); // Use add() method // to add elements in the list list.add(16); list.add(32); list.add(48); // Displaying the list System.out.println("First ArrayList: " + list); // Creating another linked list and copying // creates a shallow copy ArrayList<Integer> sec_list = (ArrayList<Integer>)list.clone(); sec_list.add(64); // Displaying the list System.out.println("First ArrayList: " + list); // Displaying the other linked list System.out.println("Second ArrayList is: " + sec_list); } } Output First ArrayList: [16, 32, 48] First ArrayList: [16, 32, 48] Second ArrayList is: [16, 32, 48, 64] Time complexity: O(N) where N is the size of ArrayList Auxiliary Space: O(N) Comment More infoAdvertise with us Next Article How to Swap Two Elements in an ArrayList in Java? S sidgautam Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-ArrayList +1 More Practice Tags : Java Similar Reads How to Declare an ArrayList with Values in Java? ArrayList is simply known as a resizable array. Declaring an ArrayList with values is a basic task that involves the initialization of a list with specific elements. It is said to be dynamic as the size of it can be changed. Proceeding with the declaration of ArrayList, we have to be aware of the co 2 min read How to Swap Two Elements in an ArrayList in Java? We can swap two elements of Array List using Collections.swap() method. This method accepts three arguments. The first argument is the ArrayList and the other two arguments are the indices of the elements. This method returns nothing. Syntax: public static void swap(List list, int a, int b); Parame 2 min read How to Copy and Add all List Elements to an Empty ArrayList in Java? We can copy and add List items in Array List using addAll() method. This method accepts a Collection (Ex. List) as an argument and adds the collection items at the end of its calling Collection (Ex. ArrayList). This method returns a boolean value. addAll() return true if the collection successfully 2 min read How to Copy or Append HashSet to Another HashSet in Java? HashSet is used to store distinct values in Java. HashSet stores the elements in random order, so there is no guarantee of the elements' order. The HashSet class implements the Set interface, backed by a hash table which is actually a HashMap instance. We can copy or append a HashSet to another Hash 4 min read How to Make a Deep Copy of Java ArrayList? The Advantage of ArrayList is it can be defined without giving a predefined size. But the disadvantage is it is more expensive to create and maintain. To have the solution for these expenses we can create a deep copy of an ArrayList. There are two types of copies that can be made the first one is a 3 min read How to Clone a List in Java? Given a list in Java, the task is to clone this list. Example: Input: list = ["Geeks", "for", "Geeks"] Output: clonedList = ["Geeks", "for", "Geeks"] Input: list = ["GeeksForGeeks", "A Computer Science", "Portal"] Output: clonedList = ["GeeksForGeeks", "A Computer Science", "Portal"] In Java, there 9 min read Like