The java.util.Deque Interface in Java


Deques (Double Ended Queues) support adding or removing elements from both ends, functioning both as a queue and a stack.

Source Code

Deque deque = new ArrayDeque();
deque.offerFirst(1); // Adds an element at the front
deque.offerLast(2); // Adds an element at the end
System.out.println(deque.pollFirst()); // Removes and returns the first element, outputs 1
System.out.println(deque.pollLast()); // Removes and returns the last element, outputs 2
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments