Java Deque getLast() 方法

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

Java Deque 接口的 getLast() 方法会检索但不会移除 deque 的最后一个元素。上述方法与 peekLast() 的区别仅在于,如果 deque 为空,前者会抛出异常。

语法

参数

不适用。

返回

上述方法用于返回 deque 的尾部。

Throw

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

示例 1

输出

The final queue is : [FAT, CAO, JAVA, DBMS]
The required answer : DBMS

示例 2

输出

The list of the elements is given as : 
[k, p, m, t]
The required answer : t

示例 3

输出

The list of the elements is given as : [2, 3, 4, 5]
The required answer : 5
下一主题Java Deque