The put(E e) method of BlockingQueue interface inserts element passed as parameter to method at the tail of this BlockingQueue, if queue is not full. If the queue is full, then this method will wait for space to become available and after space is available, it inserts the element to BlockingQueue.
public void put(E e) throws InterruptedException
Parameter: This method takes a mandatory parameter e which is the element to be inserted in LinkedBlockingQueue.
Return Value: The method does not return anything.
Exception: This method throws following exceptions:
- InterruptedException– when interruption occurred at time of waiting for queue to become available
- NullPointerException– if the element passed to method is null
Note: The put() method of BlockingQueue has been inherited from the Queue class in Java.
Below programs illustrates put(E e) method of BlockingQueue class:
Items in Queue are [Karan, Suraj, Harsh, Rahul]
Details of Employees: Employee [name=Ranjeet, position=Tester, salary=29000, Age=27] Employee [name=Sanjeet, position=Manager, salary=98000, Age=34] Employee [name=Karan, position=Analyst, salary=44000, Age=30]
- BlockingQueue take() method in Java with examples
- BlockingQueue contains() method in Java with examples
- BlockingQueue remove() method in Java with examples
- BlockingQueue remainingCapacity() method in Java with examples
- BlockingQueue poll() method in Java with examples
- BlockingQueue offer() method in Java with examples
- BlockingQueue drainTo() method in Java with examples
- BlockingQueue add() in Java with examples
- BlockingQueue Interface in Java
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.