Java LinkedBlockingDeque pollLast() 方法

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

LinkedBlockingDeque 类的 pollLast() 方法检索此双端队列的最后一个元素,并将其移除。如果此双端队列为空,则此方法返回 null。

LinkedBlockingDeque 类的 pollLast(long timeout, TimeUnit unit) 方法检索此双端队列的最后一个元素,并在指定时间内等待,直到有元素可用。

语法

参数

  1. 不适用
  2. timeout - 在放弃之前等待的时间(以 unit 指定的单位计)
  3. unit - TimeUnit,用于决定如何表示 timeout 参数

指定者:

LinkedBlockingDeque 类的 pollLast() 方法由以下接口指定:

  1. Deque<E> 接口中的 pollLast() 方法。
  2. BlockingDeque<E> 接口中的 pollLast() 方法。

返回值

pollLast() 方法返回此双端队列的尾部元素,如果此双端队列为空,则返回 null。

pollLast(long timeout, TimeUnit unit) 方法返回此双端队列的尾部元素,如果指定的等待时间过去后仍未获得元素,则返回 null。

抛出

如果方法在等待期间被中断,pollLast() 方法将抛出 InterruptedException。

示例 1

输出

Last element of the dequeis : Ramesh
Elements left in deque : [Himanshu, Rahul, Rita]

示例 2

输出

Jyoti gets the lowest wages of 1000
Vineet gets the second  lowest wages of 1500

示例 3

输出

Last element of the deque : 876
Elements in deque : [67, 109, 76]