Java LinkedBlockingDeque offerFirst() MethodThe offerFirst () method of LinkedBlockingDeque class adds the defined elements at the front of this deque. Syntax:Parameters:e - It is the element to be added. timeout - It is the time till the method has to wait before giving up, in units of unit. unit - It is the TimeUnit that decides how to interpret the timeout parameter. Specified By:The offerFirst() method of LinkedBlockingDeque class is specified by:
Return Value:The offerFirst() method returns true if the defined element is added to this deque, else returns false. Throws:The offerFirst() method throws:
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. Rohit 2. Ramesh 3. Janak 4. Vishal 5. Yatin After adding string : 1. Yogesh 2. Rohit 3. Ramesh 4. Janak 5. Vishal 6. Yatin Example 3Test it NowOutput: Exception in thread "main" java.lang.IllegalStateException: Deque full at java.util.concurrent.LinkedBlockingDeque.addFirst(Unknown Source) at mypack1.LinkedBlockingDequeOfferFirstExample3.main(LinkedBlockingDequeOfferFirstExample3.java:13) 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