| java.util.Queue
Queue | public interface Queue extends Collection<E>(Code) | | A kind of collection provides advanced operations than other basic
collections, such as insertion, extraction, and inspection.
Generally, a queue orders its elements by means of first-in-first-out. While
priority queue orders its elements according to a comparator specified or the
elements' natural order. Furthermore, a stack orders its elements
last-in-first out.
A typical queue does not allow null to be inserted as its element, while some
implementations such as LinkedList 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 queue.
Queue does not provide blocking queue methods, which will block until the
operation of the method is allowed. BlockingQueue interface defines such
methods.
|
Method Summary | |
public E | element() Gets but not removes the element in the head of the queue. | public boolean | offer(E o) Inserts the specified element into the queue provided that the condition
allows such an operation. | public E | peek() Gets but not removes the element in the head of the queue, or throws
exception if there is no element in the queue. | public E | poll() Gets and removes the element in the head of the queue, or returns null if
there is no element in the queue. | public E | remove() Gets and removes the element in the head of the queue. |
element | public E element()(Code) | | Gets but not removes the element in the head of the queue. Throws a
NoSuchElementException if there is no element in the queue.
the element in the head of the queue. throws: NoSuchElementException - if there is no element in the queue. |
offer | public boolean offer(E o)(Code) | | Inserts the specified element into the queue provided that the condition
allows such an operation. The method is generally preferable to the
collection.add(E), since the latter might throw an exception if the
operation fails.
Parameters: o - the specified element to insert into the queue. true if the operation succeeds and false if it fails. |
peek | public E peek()(Code) | | Gets but not removes the element in the head of the queue, or throws
exception if there is no element in the queue.
the element in the head of the queue or null if there is noelement in the queue. |
poll | public E poll()(Code) | | Gets and removes the element in the head of the queue, or returns null if
there is no element in the queue.
the element in the head of the queue or null if there is noelement in the queue. |
remove | public E remove()(Code) | | Gets and removes the element in the head of the queue. Throws a
NoSuchElementException if there is no element in the queue.
the element in the head of the queue. throws: NoSuchElementException - if there is no element in the queue. |
|
|