Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.
public ArrayDeque(int numElements)
Constructs an empty array deque with an initial capacity sufficient to hold the specified number of elements.
public ArrayDeque(Collection<? extends E> c)
Constructs a deque containing the elements of the specified collection, in the order they are returned by the
collection's iterator. (The first element returned by the collection's iterator becomes the first element, or front
of the deque.)
Examples
ArrayDeque() Example
package com.logicbig.example.arraydeque;
import java.util.ArrayDeque;
public class ArrayDequeExample {
public static void main(String... args) { ArrayDeque<Integer> ad = new ArrayDeque<>(); ad.add(1); ad.add(2); System.out.println(ad); } }
Output
[1, 2]
ArrayDeque(int numElements)
package com.logicbig.example.arraydeque;
import java.util.ArrayDeque;
public class ArrayDequeExample2 {
public static void main(String... args) { ArrayDeque<Integer> ad = new ArrayDeque<>(10); ad.add(1); ad.add(2); System.out.println(ad); } }
public static void main(String... args) { SortedSet<Integer> set = new TreeSet<>(Set.of(6, 1, 5)); ArrayDeque<Integer> ad = new ArrayDeque<>(set); System.out.println(ad); } }