The Wayback Machine - https://web.archive.org/web/20240618020203/https://www.geeksforgeeks.org/arraydeque-clone-method-in-java/
Open In App

ArrayDeque clone() Method in Java

Last Updated : 11 Jul, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

The Java.util.ArrayDeque.clone() method is used to return a shallow copy of this deque. It just creates a copy of the deque.

Syntax:

Array_Deque.clone()

Parameters: The method does not take any parameter.

Return Value: The method just returns a copy of the ArrayDeque.

Below programs illustrate the Java.util.ArrayDeque.clone() method:
Program 1:




// Java code to illustrate clone()
import java.util.*;
  
public class ArrayDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ArrayDeque
        ArrayDeque<String> de_que = new ArrayDeque<String>();
  
        // Use add() method to add elements into the Deque
        de_que.add("Welcome");
        de_que.add("To");
        de_que.add("Geeks");
        de_que.add("4");
        de_que.add("Geeks");
  
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque: " + de_que);
  
        // Creating another array to copy
        Deque<String> copy_deque = de_que.clone();
  
        // Displaying the copy of Deque
        System.out.println("The cloned array is: " + copy_deque);
    }
}


Output:

ArrayDeque: [Welcome, To, Geeks, 4, Geeks]
The cloned array is: [Welcome, To, Geeks, 4, Geeks]

Program 2:




// Java code to illustrate clone()
import java.util.*;
  
public class ArrayDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ArrayDeque
        ArrayDeque<Integer> de_que = new ArrayDeque<Integer>(8);
  
        // Use add() method to add elements into the Deque
        de_que.add(10);
        de_que.add(15);
        de_que.add(30);
        de_que.add(20);
        de_que.add(5);
  
        // Displaying the ArrayDeque
        System.out.println("ArrayDeque: " + de_que);
  
        // Creating another array to copy
        Deque<Integer> copy_deque = de_que.clone();
  
        // Displaying the copy of Deque
        System.out.println("The cloned array is: " + copy_deque);
    }
}


Output:

ArrayDeque: [10, 15, 30, 20, 5]
The cloned array is: [10, 15, 30, 20, 5]


Previous Article
Next Article

Similar Reads

Java 8 | ArrayDeque removeIf() method in Java with Examples
The removeIf() method of ArrayDeque is used to remove all those elements from ArrayDeque which satisfies a given predicate filter condition passed as a parameter to the method. This method returns true if some element are removed from the Vector. Java 8 has an important in-built functional interface which is Predicate. Predicate, or a condition che
3 min read
ArrayDeque offerLast() Method in Java
The Java.util.ArrayDeque.offerLast(Object element) method in Java is used to add a specific element at the end of this Deque. The function is similar to the addLast(), add() and offer() method of ArrayDeque in Java. Syntax: Array_Deque.offerLast(Object element) Parameters: The parameter element is of the type ArrayDeque and refers to the element to
2 min read
ArrayDeque toArray() Method in Java
The java.util.ArrayDeque.toArray() method is used to form an array of the same elements as that of the Deque. Basically, the method copies all the element from this deque to a new array. Syntax: Object[] arr = Array_Deque.toArray() Parameters: The method does not take any parameters. Return Value: The method returns an array containing the elements
2 min read
ArrayDeque push() Method in Java
The Java.util.ArrayDeque.push(E element) method is used to push an element into the Deque. The operation is similar to the operation in the stack. The element gets pushed onto the top of the deque. Syntax: Array_Deque.push(E element) Parameters: The parameter element is of the type ArrayDeque and refers to the element to be pushed into the deque. R
2 min read
ArrayDeque pop() Method in Java
The Java.util.ArrayDeque.pop() method in Java is used to pop an element from the deque. The element is popped from the top of the deque and is removed from the same. Syntax: Array_Deque.pop() Parameters: The method does not take any parameters. Return Value: This method returns the element present at the front of the Deque. Exceptions: The method t
2 min read
ArrayDeque offer() Method in Java
The Java.util.ArrayDeque.offer(Object element) method in Java is used to add a specific element at the end of the Deque. The function is similar to the offerLast() method of ArrayDeque in Java. Syntax: Array_Deque.offer(Object element) Parameters: The parameter element is of the type ArrayDeque and refers to the element to be added at the end of th
2 min read
ArrayDeque isEmpty() Method in Java
The Java.util.ArrayDeque.isEmpty() method in Java is used to check and verify if an ArrayDeque is empty or not. It returns True if the Deque is empty else it returns False. Syntax: Array_Deque.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if the deque is empty else it returns False. Below prog
2 min read
ArrayDeque getLast() Method in Java
The java.util.ArrayDeque.getLast() method in Java is used to retrieve or fetch the last element of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the last element of the deque.Syntax: Array_Deque.getLast() Parameters: The method does not take any parameter.Return Value: The method retur
2 min read
ArrayDeque getFirst() Method in Java
The java.util.ArrayDeque.getFirst() method in Java is used to retrieve or fetch the first element of the ArrayDeque. In the process, the method does not delete the element from the deque instead it just returns the first element of the deque. Syntax: Array_Deque.getFirst() Parameters: The method does not take any parameter. Return Value: The method
2 min read
ArrayDeque contains() Method in Java
The Java.util.ArrayDeque.contains() method in Java is used to check or verify whether a specific element is present in the Deque or not. Syntax: Array_Deque.contains(Object element) Parameters: The parameter element is of the type of ArrayDeque. This is the element that needs to be tested if it is present in the deque or not. Return Value: The meth
2 min read