Java ConcurrentLinkedQueue addAll() methodThe 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> SyntaxParameterc- It is the element to be added into this queue Specified ByThe addAll() method of ConcurrentLinkedQueue class is specified by:
Return ValueThe addAll() method returns a Boolean value true if the queue has changed as a result of this call. Otherwise, it returns false. ThrowsNullPointerException: 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 1Test it NowOutput: 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 2Test it NowOutput: Exception in thread "main" java.lang.NullPointerException atjava.util.TreeMap.put(TreeMap.java:563) atjava.util.TreeSet.add(TreeSet.java:255) at com.javaTpoint.ConcurrentLinkedQueueAddAllExample2.main(ConcurrentLinkedQueueAddAllExample2.java:10) If any element of the specified element is null, it will give you NullPointerException as shown above. Example 3Test it NowOutput: Exception in thread "main" java.lang.IllegalArgumentException at java.util.concurrent.ConcurrentLinkedQueue.addAll(ConcurrentLinkedQueue.java:526) at com.javaTpoint.ConcurrentLinkedQueueAddAllExample3.main(ConcurrentLinkedQueueAddAllExample3.java:12)
Next TopicJava ConcurrentLinkedQueue
|