Queue
operations. The implementations in this class are appropriate when
the base implementation does not allow null
elements. Methods add
, remove
, and
element
are based on offer
, poll
, and peek
, respectively, but throw
exceptions instead of indicating failure via false
or
null
returns.
A Queue
implementation that extends this class must
minimally define a method Queue#offer
which does not permit
insertion of null
elements, along with methods Queue#peek
, Queue#poll
, Collection#size
, and
Collection#iterator
. Typically, additional methods will be
overridden as well. If these requirements cannot be met, consider
instead subclassing AbstractCollection
.
This class is a member of the Java Collections Framework.
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public boolean | add(E
the element to add e)Overrides java. Implements java. Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions, returning
|
public boolean | Returns: true if this queue changed as a result of the callcollection containing elements to be added to this queue c)Overrides java. Implements java. Adds all of the elements in the specified collection to this queue. |
public void | clear()
Overrides java. Implements java. Removes all of the elements from this queue. |
public E | Returns: the head of this queueImplements java. Retrieves, but does not remove, the head of this queue. |
public E | Returns: the head of this queueImplements java. Retrieves and removes the head of this queue. |
AbstractQueue | back to summary |
---|---|
protected AbstractQueue() Constructor for use by subclasses. |
add | back to summary |
---|---|
public boolean add(E e) Overrides java. Implements java. Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions, returning
This implementation returns
|
addAll | back to summary |
---|---|
public boolean addAll(Collection<? extends E> c) Overrides java. Implements java. Adds all of the elements in the specified collection to this
queue. Attempts to addAll of a queue to itself result in
This implementation iterates over the specified collection,
and adds each element returned by the iterator to this
queue, in turn. A runtime exception encountered while
trying to add an element (including, in particular, a
|
clear | back to summary |
---|---|
public void clear() Overrides java. Implements java. Removes all of the elements from this queue. The queue will be empty after this call returns. This implementation repeatedly invokes |
element | back to summary |
---|---|
public E element() Implements java. Retrieves, but does not remove, the head of this queue. This method
differs from This implementation returns the result of
|
remove | back to summary |
---|---|
public E remove() Implements java. Retrieves and removes the head of this queue. This method differs
from This implementation returns the result of
|