Java Deque removeLast() 方法

2025 年 3 月 22 日 | 阅读需 2 分钟

Java Deque 接口的 removeLast() 方法用于检索并移除给定双端队列的最后一个元素。该方法与 pollLast() 方法的区别在于,如果给定的双端队列为空,它会抛出异常。

语法

参数

不适用

返回

上述方法用于返回给定双端队列的尾部元素。

Throw

NoSuchElementException - 如果给定的双端队列为空。

示例 1

输出

The value that needs to be removed is : World
The final deque is : 
Welcome
to
my

示例 2

输出

The value that needs to be removed is : E
The final deque is : 
W
E
B
S
I
T

示例 3

输出

The value that needs to be removed is : 98.7
The final deque is : 
55.9
22.5
77.0
下一主题Java Deque