Java LinkedBlockingDeque addAll() methodThe 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 :
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 1Test it NowOutput: Deque : [Himanshu, Janak, Ravi] Example 2Test it NowOutput: List [1, 2, 3, 4, 5] Deque : [] Ater implementind addAll() method: Deque : [1, 2, 3, 4, 5] List : [1, 2, 3, 4, 5] Example 3Test it NowOutput: 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 4Test it NowOutput: 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. Next TopicJava Linkedblockingdeque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India