deque interface java

Deque interface and ArrayDeque – Java Example

The Deque interface in java is a subtype of Queue interface. A deque is a double-ended-queue, usually pronounced as “deck”. It supports the addition and removal of items from both the ends. It can act like both stacks (LIFO) and queues (FIFO).

We can say deque provides a more versatile data structure than either stack or a queue. However it is not used often compared to stacks and queues in practice.

The hierarchy of deque interface in java is shown below

deque interface java

Deque Interface Java SE 8

The 12 deque methods for insertion, removal and retrieval of Deque elements are listed below

Deque Example

Let’s create deque using linked list and experiment some of the deque methods as shown in example below.


Deque in Collection Hierarchy

collection interface


ArrayDeque is the resizable-array implementation of the Deque interface. It extends AbstractCollection and implements Deque interface. It does not have any capacity restrictions and they grow the array size as necessary.

They are not thread safe and it does not allow to insert Null elements. ArrayDeque is faster than Stack when used as a stack and faster than Linked List when used as a queue.

Example: ArrayDeque


Related Posts


Leave a Reply

Notify of