Java ConcurrentLinkedQueue addAll() method
The addAll() method of ConcurrentLinkedQueue class appends all of the elements in the specified collection at the tail of this ConcurrentLinkedQueue. The addAll() method overrides addAll in class AbstractQueue<E>
Syntax
Parameter
c– It is the element to be added into this queue
Specified By
The addAll() method of ConcurrentLinkedQueue class is specified by:
- addAll() method in interface Collection<E>.
Return Value
The addAll() method returns a Boolean value true if the queue has changed as a result of this call. Otherwise, it returns false.
Throws
NullPointerException: This exception will throw if the specified elements in the collection are null.
IllegalArgumentException: This exception will throw if the collection is this queue.
Example 1
Output:
Before applying addAll() : Elements in queue : [] Elements in list : [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] After applying addAll : Elements in queue : [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] Elements in list : [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
Example 2
Output:
Exception in thread "main" java.lang.NullPointerException atjava.util.TreeMap.put(TreeMap.java:563) atjava.util.TreeSet.add(TreeSet.java:255) at com.tutorAspire.ConcurrentLinkedQueueAddAllExample2.main(ConcurrentLinkedQueueAddAllExample2.java:10)
If any element of the specified element is null, it will give you NullPointerException as shown above.
Example 3
Output:
Exception in thread "main" java.lang.IllegalArgumentException at java.util.concurrent.ConcurrentLinkedQueue.addAll(ConcurrentLinkedQueue.java:526) at com.tutorAspire.ConcurrentLinkedQueueAddAllExample3.main(ConcurrentLinkedQueueAddAllExample3.java:12)