Java LinkedBlockingDeque getFirst() 方法

2025 年 3 月 21 日 | 阅读 2 分钟

LinkedBlockingDeque 类的 getFirst() 方法会返回此双端队列的第一个元素,但不会将其移除。

语法

参数

不适用

指定者:

LinkedBlockingDeque 类的 getFirst() 方法是在 Deque<E> 接口中通过 getFirst() 方法指定的。

返回值

getFirst() 方法返回此双端队列的第一个元素。

抛出

如果此双端队列为空,则 getFirst() 方法会抛出 NoSuchElementException 异常。

示例 1

输出

First element in the Queue is : 987

示例 2

输出

Exception in thread "main" java.util.NoSuchElementException
	at java.util.concurrent.LinkedBlockingDeque.getFirst(Unknown Source)

示例 3

输出

Mansi got 41 bonus_points.
Vaibhav got 33 bonus_points.
Shraddha got 31 bonus_points.
Vishal got 27 bonus_points.
Shalu got 26 bonus_points.
Abhi got 19 bonus_points.

On the basis of bonus points, Promotion is awarded to : Mansi