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.
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
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
LD1: [John, Johnathan, Jones, James] Exception thrown while adding deque to itself is: java.lang.IllegalArgumentException
Example 3: Showing NullPointerException
LD1: [John, Johnathan, Jones, James] LD2: null After adding the ld2 to ld1: java.lang.NullPointerException
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.