Java LinkedBlockingDeque addFirst() methodThe addFirst() method of LinkedBlockingDeque class inserts the specified element at the front of this LinkedBlockingDeque. This method throws IllegalStateException if the specified element is null. Syntax:Parameters:e- It is the element to add Specified By:The addFirst() method of ConcurrentLinkedQueue class is specified by :
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: [1, 2, 3, 4, 5] After inserting 10 at first position [10, 1, 2, 3, 4, 5] Example 2Test it NowOutput: 1. Disha 2. Tanmay 3. Prachi 4. Garvit After adding string : 1. Diya 2. Disha 3. Tanmay 4. Prachi 5. Garvit Example 3Test it NowOutput: Exception in thread "main" java.lang.IllegalStateException: Deque full at java.util.concurrent.LinkedBlockingDeque.addFirst(LinkedBlockingDeque.java:326) at com.javaTpoint.LinkedBlockingDequeAddFirstExample3.main (LinkedBlockingDequeAddFirstExample3.java:13) Next TopicLinkedblockingdeque add() |
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