Java PriorityQueue poll() Method
Last Updated : 17 Mar 2025
The poll() method of PriorityQueue class retrieves the head of this queue, and also removes it. The method returns null if this queue is empty.
Syntax
Parameter
NA
Return Value
The poll() method returns this queue's head, and if this queue is empty returns null.
Example 1
Output:
Head of queue is: Mark Queue after using poll() method : Ramesh Robert Yasir
Example 2
Output:
Rima stood First in the class Vinni stood Second in the class Hinna stood Third in the class
Example 3
Output:
Arnavi can visit the doctor at first. Sarita can visit the doctor after the first patient. Himani can visit the doctor after the second patient.