VOOZH about

URL: https://www.geeksforgeeks.org/java/blockingdeque-addlast-method-in-java-with-examples/

⇱ BlockingDeque addLast() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BlockingDeque addLast() method in Java with Examples

Last Updated : 12 Jul, 2025
The addLast(E e) method of BlockingDeque inserts the element passed in the parameter to the end of the Deque if there is space. If the BlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. Syntax:
public void addLast(E e)
Parameters: This method accepts a mandatory parameter e which is the element to be inserted in the end of the BlockingDeque. Returns: This method does not returns anything. Exception:
  • IllegalStateException: if the element cannot be added at this time due to capacity restrictions
  • NullPointerException: if the specified element is null
Note: The addLast() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java. Below programs illustrate addLast() method of BlockingDeque: Program 1:
Output:
Blocking Deque: [7855642, 35658786, 5278367, 74381793]
Program 2: Output:
Exception in thread "main" java.lang.IllegalStateException: Deque full
 at java.util.concurrent.LinkedBlockingDeque.addLast(LinkedBlockingDeque.java:335)
 at GFG.main(GFG.java:25)
Program 3:
Output:
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 GFG.main(GFG.java:24)
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingDeque.html#addLast(E)
Comment