Deque

Deque is an interface that is a double-ended queue. It extends the Queue interface with the methods that allow access to both ends of the queue to add, look at, and remove elements from both ends.

For the Queue interface, we need six methods. Dequeue, having two manageable ends, needs 12 methods. Instead of add(), we have addFirst() and addLast(). Similarly, we can use offerFirst() and offerLast(), peekFirst() and peekLast(), and pollFirst() and pollLast(). For some reason, the methods that implement the functionality of the element() method in the Queue interface are named getFirst() and getLast() in the Dequeue interface.

Since this interface extends the Queue interface, the methods defined there can also be used to access the head ...

Get Java Projects - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.