The
addAll(Collection col) of
ConcurrentLinkedDeque which takes col as a parameter, where col is a Collection of elements (List, ArrayList, LinkedList etc). This entire Collection gets appended or added to the end of the Dequeue. This method just like add() method returns true if the Collection gets appended to the Deque.
Syntax:
public boolean addAll(Collection c)
Parameters: This function accepts a parameter
col that is the Collection of elements to be added.
Return Value: This method returns
a boolean value stating if the Collection gets appended to the Deque.
Exception: This method accepts two exceptions:
- NullPointerException: if any of its elements present in the collection is null or the collection is null.
- IllegalArgumentException: if the passed collection is existing deque itself.
Below examples illustrate the addAll() method:
Example 1: Adding Collection of Numbers to the first Collection of ConcurrentLinkedDeque
Output:
LD1: [1, 2, 3, 4]
LD2: [8, 1, 3, 5]
After adding the ld2 to ld1: [1, 2, 3, 4, 8, 1, 3, 5]
Example 2: Showing IllegalArgumentException
Output:
LD1: [John, Johnathan, Jones, James]
Exception thrown while adding deque to itself is: java.lang.IllegalArgumentException
Example 3: Showing NullPointerException