Thursday, May 21, 2026
HomeLanguagesJavaConcurrentLinkedDeque pollLast() method in Java

ConcurrentLinkedDeque pollLast() method in Java

The java.util.concurrent.ConcurrentLinkedDeque.pollLast() is an in-built method in Java which retrieves the last element of this deque and removes it. If the deque is empty, the method returns NULL.

Syntax:

Conn_Linked_Deque.pollLast()

Parameters: The function accepts no parameters.

Return Values:The function returns the last element of this deque. If this deque is empty, the function returns NULL.

Below program illustrates the use of pollFirst() method:

Program 1: This program involves deque with Integer elements.




/* Java Program Demonstrate pollLast() 
 method of ConcurrentLinkedDeque   */
  
import java.util.concurrent.*;
  
class ConcurrentLinkedDequeDemo {
    public static void main(String[] args)
    {
        ConcurrentLinkedDeque<Integer> cld = 
                     new ConcurrentLinkedDeque<Integer>();
  
        cld.addFirst(12);
        cld.addFirst(70);
        cld.addFirst(1009);
        cld.addFirst(475);
  
        // Displaying the existing LinkedDeque
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
  
        // Display and remove the Last element
        System.out.println("Element removed : "
                           + cld.pollLast());
  
        // Displaying the elements
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
    }
}


Output:

Elements inthe LinkedDeque: [475, 1009, 70, 12]
Element removed : 12
Elements inthe LinkedDeque: [475, 1009, 70]

Program 2: This program involves deque with String elements.




/* Java Program Demonstrate pollLast() 
 method of ConcurrentLinkedDeque   */
  
import java.util.concurrent.*;
  
class ConcurrentLinkedDequeDemo {
    public static void main(String[] args)
    {
        ConcurrentLinkedDeque<String> cld = 
                       new ConcurrentLinkedDeque<String>();
  
        cld.addFirst("GFG");
        cld.addFirst("Geeks");
        cld.addFirst("Gfg");
        cld.addFirst("Geeks");
  
        // Displaying the existing LinkedDeque
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
  
        // Display and remove the Last element
        System.out.println("Element removed : "
                           + cld.pollLast());
  
        // Displaying the elements
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
    }
}


Output:

Elements inthe LinkedDeque: [Geeks, Gfg, Geeks, GFG]
Element removed : GFG
Elements inthe LinkedDeque: [Geeks, Gfg, Geeks]

Reference:https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html#pollLast()

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS