Java LinkedBlockingDeque add() methodThe add() method of LinkedBlockingDeque class inserts the specified element at the tail of this LinkedBlockingDeque. The add() method overrides the add in class AbstractQueue<E> Syntax:Parameters:e- It is the element to add Specified By:The add() method of ConcurrentLinkedQueue class is specified by:
Return Value:The add() method returns a Boolean value true, if the specified element is not null. Throws:NullPointerException: This exception will throw if the specified element e, is null. IllegalStateException: This exception will throw if this deque is full Example 1Test it NowOutput: After adding 1 to the deque : [1] After adding 2 to the deque : [1, 2] After adding 3 to the deque : [1, 2, 3] After adding 4 to the deque : [1, 2, 3, 4] After adding 5 to the deque : [1, 2, 3, 4, 5] Example 2Test it NowOutput: 1. Name = Himanshu 2. Name = Jyoti 3. Name = Rahul Example 3Test it NowOutput: Deque : 71 8 18 19 Max number = 71 Min number = 8 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 com.javaTpoint.LinkedBlockingDequeAddExample4.main(LinkedBlockingDequeAddExample4.java:11) 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