Java LinkedBlockingDeque addAll() method

The addAll() method of LinkedBlockingDeque class is used to add all the elements of the specified collection at the end of this deque. This method overrides addAll() in class AbstractQueue<E>.

Syntax:

Parameters:

c- the elements to be added to this deque

Specified By:

The addAll() method of LinkedBlockingDeque class is specified by :

  1. addAll() in interface Collection<E>.
  2. addAll() in interface Deque<E>.

Overrides:

The addAll() method of LinkedBlockingDeque class overrides addAll() in class AbstractQueue<E>.

Return Value:

The addAll() method returns true if there is a change in this deque after the method call.

Throws:

The addAll() method throws:

NullPointerException - if the specified collection or any of its elements are null

IllegalArgumentException - if the collection is this deque

IllegalStateException ? if this deque is full

Example 1

Test it Now

Output:

Deque : [Himanshu, Janak, Ravi]

Example 2

Test it Now

Output:

List [1, 2, 3, 4, 5]
Deque : []
  Ater implementind addAll() method:
Deque : [1, 2, 3, 4, 5]
List : [1, 2, 3, 4, 5]

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.IllegalArgumentException
	at java.util.AbstractQueue.addAll(AbstractQueue.java:184)
	at com.javaTpoint.LinkedBlockingDequeAddAllExample3.main(LinkedBlockingDequeAddAllExample3.java:10)

If the collection is same as this deque then it will give you IllegalArgumentException.

Example 4

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 java.util.AbstractQueue.addAll(AbstractQueue.java:187)
	at com.javaTpoint.LinkedBlockingDequeAddAllExample4.main(LinkedBlockingDequeAddAllExample4.java:11)

If any element of the collection is null, it will give NullPointerException as shown above.






Latest Courses