TheQueueimplementations are grouped into general-purpose and concurrent implementations.General-Purpose Queue Implementations
As mentioned in the previous section,LinkedListimplements theQueueinterface, providing FIFO queue operations foradd,poll, and so on.The
PriorityQueueclass is a priority queue based on the heap data structure. This queue orders elements according to an order specified at construction time, which can be the elements' natural ordering or the ordering imposed by an explicitComparator.The queue retrieval operations
poll,remove,peek, andelement access the element at the head of the queue. The head of the queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements; ties are broken arbitrarily.
PriorityQueueand its iterator implement all of the optional methods of theCollectionandIteratorinterfaces. The iterator provided in methoditeratoris not guaranteed to traverse the elements of thePriorityQueuein any particular order. If you need ordered traversal, consider usingArrays.sort(pq.toArray()).Concurrent Queue Implementations
Thejava.util.concurrentpackage contains a set of synchronizedQueueinterfaces and classes.BlockingQueueextendsQueuewith operations that wait for the queue to become nonempty when retrieving an element and for space to become available in the queue when storing an element. This interface is implemented by the following classes:
LinkedBlockingQueue an optionally bounded FIFO blocking queue backed by linked nodesArrayBlockingQueue a bounded FIFO blocking queue backed by an arrayPriorityBlockingQueue an unbounded blocking priority queue backed by a heapDelayQueue a time-based scheduling queue backed by a heapSynchronousQueue a simple rendezvous mechanism that uses theBlockingQueueinterface