ConcurrentLinkedDeque peek() method in Java with Example Last Updated : 24 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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 // 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 // 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 Comment More infoAdvertise with us Next Article ConcurrentLinkedDeque peekFirst() method in Java M MerlynShelley Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2018 Java-Collections Java - util package Java-Functions Java-ConcurrentLinkedDeque +3 More Practice Tags : JavaJava-Collections Similar Reads ConcurrentLinkedDeque poll() method in Java with Example The poll() method of ConcurrentLinkedDeque returns the front element in the Deque container and deletes it. It returns null if the container is empty. Syntax: public E poll() Parameters: This method does not accept any parameters. Returns: This method returns front element of the Deque container if 2 min read ConcurrentLinkedDeque pop() method in Java with Examples The Java.util.ConcurrentLinkedDeque.pop() method in Java is used to pop an element from the ConcurrentLinkedDeque. The element is popped from the top of the ConcurrentLinkedDeque and is removed from the same.Syntax: ConcurrentLinkedDeque.pop() Parameters: The method does not take any parameters.Retu 2 min read ConcurrentLinkedDeque offer() method in Java with Examples The java.util.concurrent.ConcurrentLinkedDeque.offer() method is an inbuilt method in Java which inserts the specified element, passed as a parameter, to the deque. Syntax: public boolean offer(E elem) Parameters: The method accepts a parameter elem which species the element to be inserted to the de 2 min read ConcurrentLinkedDeque iterator() method in Java with Example The Java.util.concurrent.ConcurrentLinkedDeque.iterator() method is used to return an iterator of the same elements as that of the ConcurrentLinkedDeque. The elements are returned in random order from what was present in the deque. Syntax: Iterator iterate_value = ConcurrentLinkedDeque.iterator(); P 2 min read 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 paramete 2 min read 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 pa 2 min read Like