Monday, July 27, 2026
HomeLanguagesJavaConcurrentLinkedDeque peekFirst() method in Java

ConcurrentLinkedDeque peekFirst() method in Java

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

Syntax:

Conn_Linked_Deque.peekFirst() 

Parameters: This function does not accepts any parameter.

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

Below programs illustrate the peekFirst() method:

Program 1: This program involves deque with Integer elements.




// Java Program Demonstrate peekFirst()
// 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 first element
        System.out.println("First Element in"
                   + "the LinkedDeque: " + cld.peekFirst());
    }
}


Output:

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

Program 2: This program involves deque with String elements.




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


Output:

Elements inthe LinkedDeque: [Geeks, Lazyroar, Gfg, GFG]
First Element inthe LinkedDeque: Geeks

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

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS