ConcurrentLinkedDeque element() method in Java
The java.util.concurrent.ConcurrentLinkedDeque.element() is an in-built function in java which retrieves but does not remove the head of the queue represented by deque i.e the first element of deque.
Parameter: This method has no parameters.
Return Value: This method returns the first element in the deque.
Exception: This method will throw NoSuchElementException if the deque is empty.
Below programs illustrate the ConcurrentLinkedDeque.element() method:
Program 1: This program involves a ConcurrentLinkedDeque of Integer type.
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.
ConcurrentLinkedDeque: [12, 70, 1009, 475] The Head of deque is: 12
Program 2: This program involves a ConcurrentLinkedDeque of String type.
ConcurrentLinkedDeque: [Gfg, Geeks, Programming, contribute] The Head of deque is: Gfg