The java.util.concurrent.ConcurrentLinkedDeque.getFirst() method is an in-built method in Java which returns the first element of the deque container.
Parameters: The method does not accept any parameter.
Return Value: The method returns the first element present in the Deque.
Exception: The function throws a NoSuchElementException when the deque is empty.
Below programs illustrate the ConcurrentLinkedDeque.getFirst() method :
Elements in the Deque: [Welcome, To, Geeks, 4, Geeks] The first element is: Welcome
java.util.NoSuchElementException Elements in the Deque: [12, 43, 29, 16, 70] The first element is: 12
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.