The offer(E e) method of BlockingDeque inserts the element passed in the parameter to the end of the Deque. If the container’s capacity has exceeded, then it does not returns an exception as in case of add() and addFirst() function.
public boolean offer(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 returns true if the element has been inserted, else it returns false.
Note: The offer() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java.
Below programs illustrate offer() method of BlockingDeque:
The element 10 cannot be inserted as capacity is full Blocking Deque: [7855642, 35658786, 5278367, 74381793]
The element 'hii' cannot be inserted as capacity is full Blocking Deque: [abc, gopu, geeks, richik]
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.