public class PriorityQueue<T:>
A binary heap priority queue.
The comparator defines priority: a negative result means that the first value has higher priority, so ArrayList.intComparator creates a min-heap. Reverse the comparator to create a max-heap. Equal-priority elements are not stable.
Adding and removing the highest-priority element are O(log n). Peeking is O(1). The queue does not support changing an element’s priority in place; remove and re-add it after changing any fields used by the comparator.
construct(Comparator<T> comparator)construct(Comparator<T> comparator, int initialCapacity)add(T value)Adds an element to the queue.
offer(T value)Alias for add().
peek() returns TReturns the highest-priority element, or null if empty.
poll() returns TRemoves and returns the highest-priority element, or null if empty.
remove() returns TAlias for poll().
size() returns intReturns the number of queued elements.
isEmpty() returns booleanReturns whether the queue is empty.
clear()Removes all elements while retaining the backing storage.