When using a capacity-restricted deque, it is generally preferable to use method offerLast E. Retrieves and removes the last element of this deque, or returns null if this deque is empty.
When a deque is used as a stack, elements are pushed and popped from the beginning of the deque. Here is how it looks:.
Elements are added at the end of the deque and removed from the beginning. The word Deque is pronounced like a "deck" of cards. Here is an example of adding an element to the end of a Java Deque: The Deque interface, pronounced as "deck" , represents a double-ended queue. Would you like to add a better answer? Returna an iterator for this deque.
Use is subject to license terms. Comments Edit Answer Report. The first way of iterating the elements of a Deque is to obtain an Iterator from the Deque and iterate the elements via that.
Since Java Deque is an interface you need to instantiate a concrete implementation of the interface in order to use it.
Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions. Ask Question. All rights reserved.
Returns true if this deque contained the specified element or equivalently, if this deque changed as a result of the call.
Here is an example of iterating the elements of a Java Deque via an Iterator:.
This interface is a member of the Java Collections Framework. The removeFirst and removeLast functions remove the first and last elements of the deque respectively.
The code snippet that demonstrates this is given as follows. This method is equivalent to addFirst E.
The remove method returns the element that is removed from the Deque. Retrieves and removes the last element of this deque. This method differs from peekFirst only in that it throws an exception if this deque is empty.