ConcurrentLinkedDeque peekLast() method in Java

The java.util.concurrent.ConcurrentLinkedDeque.peekLast() is an in-built method in Java which
retrieves the last element of this deque container without removing it. The function returns NULL if the deque is empty.

Syntax:

Conn_Linked_Deque.peekLast()

Parameters: The function does not accepts any parameter.



Return Values: The function returns the last element present in this deque and returns NULL when the deque is empty.

Below programs illustrate the use of peekLast() method:

Program 1: This program involves deque with Integer elements.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program Demonstrate peekLast()
// 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(110);
        cld.addFirst(55);
        cld.addFirst(76);
  
        // Displaying the existing LinkedDeque
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
  
        // Displaying the last element
        System.out.println("Last Element in"
                    + "the LinkedDeque: " + cld.peekLast());
    }
}

chevron_right


Output:

Elements inthe LinkedDeque: [76, 55, 110, 12]
Last Element inthe LinkedDeque: 12

Program 2: This program involves deque with String elements.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program Demonstrate peekLast()
// 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("Gfg");
        cld.addFirst("GeeksforGeeks");
        cld.addFirst("Geeks");
  
        // Displaying the existing LinkedDeque
        System.out.println("Elements in"
                           + "the LinkedDeque: " + cld);
  
        // Displaying the last element
        System.out.println("Last Element in"
                   + "the LinkedDeque: " + cld.peekLast());
    }
}

chevron_right


Output:

Elements inthe LinkedDeque: [Geeks, GeeksforGeeks, Gfg, GFG]
Last Element inthe LinkedDeque: GFG

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



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.