Java LinkedBlockingDeque pollLast() Method

The pollLast() method of LinkedBlockingDeque class retrieves the last element of this deque, and also removes it. This method returns null if this deque is empty.

The pollLast(long timeout, TimeUnit unit) method of LinkedBlockingDeque class retrieves the last element of this deque, awaiting till the specified time is essential for an element to be available.

Syntax:

Parameters:

  1. NA
  2. timeout - It is the time to wait before giving up(in units of the unit)
  3. unit - It is the TimeUnit deciding how to represent the timeout parameter

Specified By:

The pollLast() method of LinkedBlockingDeque class is specified by :

  1. pollLast() method in interface Deque<E>.
  2. pollLast() method in interface BlockingDeque<E>.

Return Value:

The pollLast() method returns this deque'stail, and if this deque is empty returns null.

The pollLast(long timeout, TimeUnit unit) method returns this deque's tail, or null if the assigned waiting time passes before the element is available.

Throws:

The pollLast() method throws InterruptedException if the method is disrupted while waiting.

Example 1

Test it Now

Output:

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

Example 2

Test it Now

Output:

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

Example 3

Test it Now

Output:

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





Latest Courses