PriorityQueue Class
This lesson provides some more detail on the built-in methods of the PriorityQueue class in Java.
We'll cover the following
PriorityQueue
A PriorityQueue is used to process objects based on their priority. Like a queue, it follows the first-in-first-out algorithm and is used when the elements need to be processed according to the priority. It is based on the priority heap. The elements of the priority queue are ordered according to the natural ordering, or by a comparator provided when the queue is constructed.
Some methods supported are:
add() - Add elements at the tail of queue.
peek() - View the head of the queue without removing it. Returns Null if the queue is empty.
remove() - Removes and returns the head of the queue. Returns null if the queue is empty. Throws an exception when queue is empty.
poll() - Removes and returns the head of the queue.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.