Queue Interface
suggest changeBasics
A Queue is a collection for holding elements prior to processing. Queues typically, but not necessarily, order elements in a FIFO (first-in-first-out) manner.
The head of the queue is the element that would be removed by a call to remove or poll. In a FIFO queue, all new elements are inserted at the tail of the queue.
The Queue Interface
public interface Queue<E> extends Collection<E> {
boolean add(E e);
boolean offer(E e);
E remove();
E poll();
E element();
E peek();
}
Each Queue method exists in two forms:
- one throws an exception if the operation fails;
- the other returns a special value if the operation fails (either
nullorfalsedepending on the operation).
| Type of operation | Throws exception | Returns special value |
|---|---|---|
| Insert | add(e) |
offer(e) |
| Remove | remove() |
poll() |
| Examine | element() |
peek() |
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents