The pop() method of LinkedBlockingDeque pops an element from the stack represented by this deque. In other words, it removes and returns the first element of this deque. It returns null if the container is empty.
public E pop()
Parameters: This method does not accept any parameters.
Returns: This method returns the element at the front of this deque (which is the top of the stack represented by this deque). It throws an NoSuchElementException if the deque is empty.
Below programs illustrate pop() method of LinkedBlockingDeque:
Linked Blocking Deque: [74381793, 5278367, 35658786, 7855642] Front element in Deque: 74381793 Linked Blocking Deque: [5278367, 35658786, 7855642]
Exception in thread "main" java.util.NoSuchElementException at java.util.concurrent.LinkedBlockingDeque.removeFirst(LinkedBlockingDeque.java:453) at java.util.concurrent.LinkedBlockingDeque.pop(LinkedBlockingDeque.java:777) at GFG.main(GFG.java:27)
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.