Javatpoint Logo
Javatpoint Logo

Java PriorityQueue poll() Method

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

Test it Now

Output:

Head of queue is: Mark
Queue after using poll() method : 
Ramesh
Robert
Yasir

Example 2

Test it Now

Output:

Rima stood First in the class
Vinni stood Second in the class
Hinna stood Third in the class

Example 3

Test it Now

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. 
Next TopicJava PriorityQueue



Help Others, Please Share

facebook twitter pinterest