Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.
Constructs an empty array deque with an initial capacity sufficient to hold the specified number of elements.
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.)
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);
}
}
Output
[1, 2]
ArrayDeque(Collection<? extends E> c) Example:
package com.logicbig.example.arraydeque;
import java.util.ArrayDeque;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
public class ArrayDequeExample3 {
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);
}
}
Output
[1, 5, 6]