The put(E e) method of LinkedBlockingDeque inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque). If the Deque is capacity restricted, then it will wait for the space to become available.
public void put(E e)
Parameters: This method accepts a mandatory parameter e which is the element to be inserted at the end of the LinkedBlockingDeque.
Returns: This method does not return anything.
Exceptions: The program throws two exceptions as shown below:
- NullPointerException – if the specified element is null
- InterruptedException – if interrupted while waiting
Below programs illustrate put() method of LinkedBlockingDeque:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.LinkedBlockingDeque.putLast(LinkedBlockingDeque.java:390) at java.util.concurrent.LinkedBlockingDeque.put(LinkedBlockingDeque.java:649) at GFG.main(GFG.java:22)
Runtime Errors: Max real time limit exceeded due to either by heavy load on server or by using sleep function
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.