Java ArrayBlockingQueue peek() 方法

2025年1月7日 | 阅读 2 分钟

Java ArrayBlockingQueue 类的 peek() 方法检索此队列的头部,但不移除它。如果队列为空,则该方法返回 null。

语法

参数

不适用

指定者:

ArrayBlockingQueue 类的 peek() 方法在 Queue 接口中由 peek() 方法指定.

返回值

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

示例 1

输出

Head of queue : Reema
        Queue : [Reema, Rahul, Rita, Ramesh]

示例 2

输出

Hinna got 97 marks.
Vinni got 87 marks.
Rima got 77 marks.
Topper of the class is Hinna

示例 3

输出

Head of queue is : null