Java ArrayDeque.clone()

Syntax

ArrayDeque.clone() has the following syntax.

public ArrayDeque <E> clone()

Example

In the following code shows how to use ArrayDeque.clone() method.


/* w  ww  . ja  v  a  2  s  .  co m*/
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
   public static void main(String[] args) {
      
      
     ArrayDeque<Integer>  deque1 = new ArrayDeque<Integer> (8);

      
      deque1.add(3);
      deque1.add(2);
      deque1.add(1);
      deque1.add(18);
      
      // clone the first deque,
      Deque<Integer>  deque2 = deque1.clone();
           
      // print all the elements available in deque2
      System.out.println(deque2);
   }
}

The code above generates the following result.