Close

Java Collections - ArrayDeque Constructors Examples

Java Collections Java Java API 


Class:

java.util.ArrayDeque

java.lang.Objectjava.lang.Objectjava.util.AbstractCollectionjava.util.AbstractCollectionjava.util.CollectionCollectionjava.util.ArrayDequejava.util.ArrayDequejava.util.DequeDequejava.lang.CloneableCloneablejava.io.SerializableSerializableLogicBig

Constructors:

public ArrayDeque()

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);
}
}

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]




See Also