Java LinkedBlockingDeque pop() Method

The pop() method of LinkedBlockingDeque class returns the first element of this deque, and also removes it. The result returned by pop() method is similar to that returned by Deque.removeFirst().

Syntax:

Parameters:

NA

Specified By:

The pop() method of LinkedBlockingDeque class is specified by pop() method in interface Deque<E>.

Return Value:

The pop() method returns the foremost element of this deque.

Throws:

The pop() method throws NoSuchElementException if this deque is empty.

Example 1

Test it Now

Output:

First element of the dequeis :Himanshu
Elements left in deque : [Rahul, Rita, Ramesh]

Example 2

Test it Now

Output:

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 com.javaTpoint.LinkedBlockingDequePopExample2.main(LinkedBlockingDequePopExample2.java:9)

Example 3

Test it Now

Output:

Reema       Panda     [email protected]
Geetanjali  Sharma    [email protected]
VineetTanjea    [email protected]
HimanshuBhardwaj  [email protected]





Latest Courses