Java LinkedBlockingDeque clear() method

21 Mar 2025 | 2 min read

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

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

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.
  • offerLast()

    Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class adds the defined elements at the end of this deque, only if the deque&#39;s capacity allows so. Syntax: public boolean offerLast(E e) public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException Parameters: e - It is the element to be...

    2 min read

  • add()

    Java LinkedBlockingDeque method The method of LinkedBlockingDeque class inserts the specified element at the tail of this LinkedBlockingDeque. The method overrides the add in class AbstractQueue&lt;E&gt; Syntax: public boolean add(E e) Parameters: e- It is the element to add Specified By: The method of ConcurrentLinkedQueue class is specified...

    2 min read

  • iterator()

    Java LinkedBlockingDeque method The method of LinkedBlockingDeque class returns an iterator across the elements of this deque in the appropriate order. The elements returned will be in the order from head to tail. Syntax: public Iterator&lt;E&gt; Parameters: NA Specified By: The method of LinkedBlockingDeque class is specified by: ...

    3 min read

  • poll()

    Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class retrieves the head of the queue corresponding to this deque, and also removes it. This method returns null if this deque is empty. The poll(long timeout, TimeUnit unit) method of LinkedBlockingDequeclass retrieves the head of the queue...

    2 min read

  • peekFirst()

    Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class retrieves this deque&#39;s first element, but doesn&#39;t remove it. The method returns null if this deque is empty. Syntax: public E Parameters: NA Specified By: The method of LinkedBlockingDeque class is specified by method in interface Deque&lt;E&gt;. Return Value: The ...

    3 min read

  • contains()

    Java LinkedBlockingDeque Method The method is used to check the presence of the specified element in the deque. If the element is present in the deque, then this method returns true otherwise it returns false. Syntax: public boolean contains(Object o) Parameters: o - this is the object that...

    2 min read

  • offerFirst()

    Java LinkedBlockingDeque Method The offerFirst () method of LinkedBlockingDeque class adds the defined elements at the front of this deque. Syntax: public boolean offerFirst(E e) public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException Parameters: e - It is the element to be added. timeout - It is the time...

    3 min read

  • peekLast()

    Java LinkedBlockingDeque Method The method of LinkedBlockingDeque class retrieves this deque&#39;s last element, but doesn&#39;t remove it. The method returns null if this deque is empty. Syntax: public E peekLast () Parameters: NA Specified By: The peekLast () method of LinkedBlockingDeque class is specified by method in interface Deque&lt;E&gt;. Return...

    3 min read

  • addFirst()

    Java LinkedBlockingDeque method The method of LinkedBlockingDeque class inserts the specified element at the front of this LinkedBlockingDeque. This method throws IllegalStateException if the specified element is null. Syntax: public Boolean addFirst(E e) Parameters: e- It is the element to add Specified By: The method of ConcurrentLinkedQueue class is...

    1 min read




  • close