Java LinkedTransferQueue put() Method

21 Mar 2025 | 1 min read

The put() method of LinkedTransferQueue adds the defined element at the tail of this queue. It waits till the space becomes available if queue is full.

Syntax:

Parameters:

e - This is the element to be added.

Specified By:

The put() method of LinkedTransferQueue class is specified by put() method in interface BlockingQueue.

Return:

NA

Throws:

NullPointerException - This exception will throw if the specified element is null.

Example 1

Output:

 Elements in queue : [67, 109, 76, 876, 2] 

Example 2

Output:

 John Harry Kristen Peter 

Example 3

Output:

 Exception in thread "main" java.lang.NullPointerException	at java.base/java.util.concurrent.LinkedTransferQueue.xfer(Unknown Source)	at java.base/java.util.concurrent.LinkedTransferQueue.put(Unknown Source)	at tests.LinkedTransferQueuePutExample3.main(LinkedTransferQueuePutExample3.java:11)