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.
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.
Elements inthe LinkedDeque: [76, 55, 110, 12] First Element inthe LinkedDeque: 76
Program 2: This program involves deque with String elements.
Elements inthe LinkedDeque: [Geeks, GeeksforGeeks, Gfg, GFG] First Element inthe LinkedDeque: Geeks
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.