How to clone an ArrayList to another ArrayList in Java? Last Updated : 19 Jul, 2022 Comments Improve Suggest changes 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 clone an ArrayList to another 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 Pass ArrayList Object as Function Argument in java? ArrayList class in Java is basically a resizable array i.e. it can grow and shrink in size dynamically according to the values that we add or remove to/from it. It is present in java.util package. If we want to pass an ArrayList as an argument to a function then we can easily do it using the syntax 4 min read How to Convert ArrayList to HashSet in Java? ArrayList: In Java, ArrayList can have duplicates as well as maintains insertion order. HashSet: HashSet is the implementation class of Set. It does not allow duplicates and uses Hashtable internally. There are four ways to convert ArrayList to HashSet : Using constructor.Using add() method by itera 3 min read 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 Objects Can an ArrayList Hold in Java? ArrayList is a part of the collection framework and is present in java.util package. It provides us with dynamic arrays in Java just as Vector in C++. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. In order to understan 3 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 Convert ArrayList to Vector in Java There are several ways to convert ArrayList to Vector. We can use a vector constructor for converting ArrayList to vector. We can read ArrayList elements one by one and add them in vector. Approach 1: (Using Vector Constructor) Create an ArrayList.Add elements in ArrayList.Create a vector and pass t 3 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 Convert an ArrayList Containing Integers to Primitive Int Array? In Java, ArrayList is the pre-defined class of the Java Collection Framework. It is part of the java.util package. ArrayList can be used to add or remove an element dynamically in the Java program. It can be snipped dynamically based on the elements added or removed into the ArrayList. In this artic 2 min read Like