Java LinkedBlockingDeque clear() method

The clear() method of LinkedBlockingDeque class automatically withdraws all the elements from this deque. The deque becomes empty, after calling this method.

Syntax:

Parameters:

NA

Specified By:

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

Override:

The clear() method of class LinkedBlockingDeque overrides the clear() method of class AbstractQueue<E>.

Example 1

Test it Now

Output:

Deque : [23, 123, 12]
After applying clear() method :  
Deque : []

Example 2

Output:

1. Sugar
2. Salt
3. Potato
4. Rice
Is Your shopping done.?
true/false : Your queue is empty.
Make a new list.

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.NullPointerException
	at java.util.concurrent.LinkedBlockingDeque.offerLast(LinkedBlockingDeque.java:357)
	at java.util.concurrent.LinkedBlockingDeque.addLast(LinkedBlockingDeque.java:334)
	at java.util.concurrent.LinkedBlockingDeque.add(LinkedBlockingDeque.java:633)
	at com.javaTpoint.LinkedBlockingDequeClearExample3.main(LinkedBlockingDequeClearExample3.java:7)





Latest Courses