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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access