Sunday, June 14, 2026
HomeLanguagesJavaConcurrentLinkedDeque peek() method in Java with Example

ConcurrentLinkedDeque peek() method in Java with Example

The java.util.ConcurrentLinkedDeque.peek() method in Java is used to retrieve or fetch the element at the head of the Deque. The element retrieved does not get deleted or removed from the Deque instead the method just returns it. If no element is present in the deque then Null is returned.

Syntax:

Array_Deque.peek()

Parameters: The method does not take any parameter.

Return Value: The method returns the element at the head of the Deque.

Below programs illustrate the Java.util.ConcurrentLinkedDeque.peek() method:

Program 1:




// Java code to illustrate peek()
  
import java.util.concurrent.*;
  
public class ConcurrentLinkedDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ConcurrentLinkedDeque
        ConcurrentLinkedDeque<String> de_que
            = new ConcurrentLinkedDeque<String>();
  
        // Use add() method to add elements into the Deque
        de_que.add("Welcome");
        de_que.add("To");
        de_que.add("Geeks");
        de_que.add("4");
        de_que.add("Geeks");
  
        // Displaying the ConcurrentLinkedDeque
        System.out.println("Initial ConcurrentLinkedDeque: "
                           + de_que);
  
        // Displaying the head
        System.out.println("The element at head is: "
                           + de_que.peek());
  
        // Displaying the ConcurrentLinkedDeque after operation
        System.out.println("Final ConcurrentLinkedDeque: "
                           + de_que);
    }
}


Output:

Initial ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks]
The element at head is: Welcome
Final ConcurrentLinkedDeque: [Welcome, To, Geeks, 4, Geeks]

Program 2:




// Java code to illustrate peek()
import java.util.concurrent.*;
  
public class ConcurrentLinkedDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ConcurrentLinkedDeque
        ConcurrentLinkedDeque<Integer> de_que
            = new ConcurrentLinkedDeque<Integer>();
  
        // Use add() method to add elements into the Deque
        de_que.add(10);
        de_que.add(15);
        de_que.add(30);
        de_que.add(20);
        de_que.add(5);
  
        // Displaying the ConcurrentLinkedDeque
        System.out.println("Initial ConcurrentLinkedDeque: "
                           + de_que);
  
        // Displaying the head
        System.out.println("The element at head is: "
                           + de_que.peek());
  
        // Displaying the ConcurrentLinkedDeque after operation
        System.out.println("Final ConcurrentLinkedDeque: "
                           + de_que);
    }
}


Output:

Initial ConcurrentLinkedDeque: [10, 15, 30, 20, 5]
The element at head is: 10
Final ConcurrentLinkedDeque: [10, 15, 30, 20, 5]

Program 3: For an empty deque:




// Java code to illustrate peek()
import java.util.concurrent.*;
  
public class ConcurrentLinkedDequeDemo {
    public static void main(String args[])
    {
        // Creating an empty ConcurrentLinkedDeque
        ConcurrentLinkedDeque<Integer> de_que
            = new ConcurrentLinkedDeque<Integer>();
  
        // Displaying the ConcurrentLinkedDeque
        System.out.println("ConcurrentLinkedDeque: "
                           + de_que);
  
        // Displaying the head
        System.out.println("The element at head is: "
                           + de_que.peek());
    }
}


Output:

ConcurrentLinkedDeque: []
The element at head is: null
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS