java.util · java.base · since Java 1.5

PriorityQueue

declaration
public class PriorityQueue<E> extends AbstractQueue<E>
        implements Serializable

Binary-heap queue: poll() always yields the smallest element per natural order or a Comparator. Iteration order is heap order, NOT sorted order.

Key methods

PriorityQueue()Natural ordering — elements must implement Comparable.
PriorityQueue(Comparator<? super E> cmp)Custom priority.
boolean offer(E)Insert — O(log n); the queue is unbounded so this never returns false.
E poll()Remove the minimum — O(log n), null if empty.
E peek()Inspect the minimum — O(1), null if empty.