java.util.Deque<E> |
Known Indirect Subclasses
|
A kind of collection that can insert or remove element at both ends("double ended queue"). Mostly a deque has no limit of its size.
Extending from Queue, a deque can be used as a Queue which behavior is first-in-first-out. Furthermore, a deque can also be used as a Stack(legacy class) which behavior is last-in-first-out.
A typical deque does not allow null to be inserted as its element, while some implementations allow it. But null should not be inserted even in these implementations, since method poll return null to indicate that there is no element left in the deque.
A deque can also remove interior elements by removeFirstOccurrence and removeLastOccurrence methods. A deque can not access elements by index.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Inserts an element at the head of this deque if it dose not violate size
limit immediately.
| |||||||||||
Inserts an element at the tail of this deque if it dose not violate size
limit immediately.
| |||||||||||
Returns the iterator in reverse order, from tail to head.
| |||||||||||
Gets but not removes the head element of this deque.
| |||||||||||
Gets but not removes the tail element of this deque.
| |||||||||||
Inserts an element at the head of this deque unless it would violate size
limit.
| |||||||||||
Inserts an element at the tail of this deque unless it would violate size
limit.
| |||||||||||
Gets but not removes the head element of this deque.
| |||||||||||
Gets but not removes the tail element of this deque.
| |||||||||||
Gets and removes the head element of this deque.
| |||||||||||
Gets and removes the tail element of this deque.
| |||||||||||
Pops the head element of the deque, just same as removeFirst().
| |||||||||||
Pushes the element to the deque(at the head of the deque), just same as
addFirst(E).
| |||||||||||
Gets and removes the head element of this deque.
| |||||||||||
Removes the first equivalent element of the specified object.
| |||||||||||
Gets and removes the tail element of this deque.
| |||||||||||
Removes the last equivalent element of the specified object.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface java.lang.Iterable
| |||||||||||
From interface java.util.Collection
| |||||||||||
From interface java.util.Queue
|
Inserts an element at the head of this deque if it dose not violate size limit immediately. It is better to use offerFirst(E) if a deque is size-limited.
e | the element |
---|
IllegalStateException | if it can not add now due to size limit |
---|---|
ClassCastException | if the class of element can not be added into this deque |
NullPointerException | if the element is null and the deque can not contain null element |
IllegalArgumentException | if the element can not be added due to some property. |
Inserts an element at the tail of this deque if it dose not violate size limit immediately. It is better to use offerLast(E) if a deque is size-limited.
e | the element |
---|
IllegalStateException | if it can not add now due to size limit |
---|---|
ClassCastException | if the class of element can not be added into this deque |
NullPointerException | if the element is null and the deque can not contain null element |
IllegalArgumentException | if the element can not be added due to some property. |
Returns the iterator in reverse order, from tail to head.
Gets but not removes the head element of this deque. This method throws an exception if the deque is empty.
NoSuchElementException | if the deque is empty |
---|
Gets but not removes the tail element of this deque. This method throws an exception if the deque is empty.
NoSuchElementException | if the deque is empty |
---|
Inserts an element at the head of this deque unless it would violate size limit. It is better than the addFirst(E) method in a size-limited deque, because the latter one may fail to add the element only by throwing an exception.
e | the element |
---|
ClassCastException | if the class of element can not be added into this deque |
---|---|
NullPointerException | if the element is null and the deque can not contain null element |
IllegalArgumentException | if the element can not be added due to some property. |
Inserts an element at the tail of this deque unless it would violate size limit. It is better than the addLast(E) method in a size-limited deque, because the latter one may fail to add the element only by throwing an exception.
e | the element |
---|
ClassCastException | if the class of element can not be added into this deque |
---|---|
NullPointerException | if the element is null and the deque can not contain null element |
IllegalArgumentException | if the element can not be added due to some property |
Gets but not removes the head element of this deque. This method returns null if the deque is empty.
Gets but not removes the tail element of this deque. This method returns null if the deque is empty.
Gets and removes the head element of this deque. This method returns null if the deque is empty.
Gets and removes the tail element of this deque. This method returns null if the deque is empty.
Pops the head element of the deque, just same as removeFirst().
NoSuchElementException | if the deque is empty |
---|
Pushes the element to the deque(at the head of the deque), just same as addFirst(E).
e | the element |
---|
IllegalStateException | if it can not add now due to size limit |
---|---|
ClassCastException | if the class of element can not be added into this deque |
NullPointerException | if the element is null and the deque can not contain null element |
IllegalArgumentException | if the element can not be added due to some property. |
Gets and removes the head element of this deque. This method throws an exception if the deque is empty.
NoSuchElementException | if the deque is empty |
---|
Removes the first equivalent element of the specified object. If the deque does not contain the element, it is unchanged and returns false.
o | the element to be removed |
---|
ClassCastException | if the class of the element is incompatible with the deque |
---|---|
NullPointerException | if the element is null and the deque can not contain null element |
Gets and removes the tail element of this deque. This method throws an exception if the deque is empty.
NoSuchElementException | if the deque is empty |
---|
Removes the last equivalent element of the specified object. If the deque does not contain the element, it is unchanged and returns false.
o | the element to be removed |
---|
ClassCastException | if the class of the element is incompatible with the deque |
---|---|
NullPointerException | if the element is null and the deque can not contain null element |