The ArrayDeque Class in java

Java SE 6 added the ArrayDeque class, which extends AbstractCollection and implements the Deque interface. It adds no methods of its own. ArrayDeque creates a dynamic array and has no capacity restrictions. (The Deque interface supports implementations that restrict capacity, but does not require such restrictions.) ArrayDeque is a generic class that has this declaration:

class ArrayDeque<E>

Here, specifies the type of objects stored in the collection.

ArrayDeque defines the following constructors:

ArrayDeque( )

ArrayDeque(int size)

ArrayDeque(Collection<? extends E> c)

Demonstrate ArrayDeque

import java.util.*;

class ArrayDequeDemo {

public static void main(String args[]) { // Create a tree set.

ArrayDeque<String> adq = new ArrayDeque<String>();

//Use an ArrayDeque like a stack. adq.push("A");

adq.push("B");

adq.push("D");

adq.push("E");

adq.push("F");

System.out.print("Popping the stack: ");

while(adq.peek() != null) System.out.print(adq.pop() + " ");

System.out.println();

}

}

The output is shown here:

Popping the stack: F E D B A

Leave a Comment