Java PriorityQueue poll() 方法

2024 年 11 月 9 日 | 阅读 2 分钟

PriorityQueue 类的 poll() 方法会检索此队列的头部,并将其移除。如果此队列为空,则该方法返回 null。

语法

参数

不适用

返回值

poll() 方法返回此队列的头部,如果此队列为空,则返回 null。

示例 1

输出

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

示例 2

输出

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

示例 3

输出

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.