Thursday, October 23, 2025
HomeLanguagesJavaLinkedTransferQueue put() method in Java

LinkedTransferQueue put() method in Java

The java.util.concurrent.LinkedTransferQueue.put() method is an in-built function in Java which is used to insert an element in this queue. It waits till the space becomes available if queue is full.

Syntax:

LinkedTransferQueue.put(E e)

Parameters: The function accepts a single parameter e i.e. the element to be inserted.

Return Value: The function does not return anything.

Exception: The function shows NullPointerException when the specified element is Null.

Below programs illustrate the LinkedTransferQueue.put() method:

Program 1: Inserting Integers in the queue.




/* Java Program Demonstrate put()
method of LinkedTransferQueue */
  
import java.util.concurrent.*;
  
class LinkedTransferQueuePutExample1 {
    public static void main(String[] args)
    {
        // Initializing the queue
        LinkedTransferQueue<Integer> queue = 
                 new LinkedTransferQueue<Integer>();
  
        // Adding elements to this queue
        for (int i = 10; i <= 15; i++)
            queue.put(i);
  
        // Printing the elements of the queue
        System.out.println("The elements in the queue are:");
        for (Integer i : queue)
            System.out.print(i + " ");
    }
}


Output:

The elements in the queue are:
10 11 12 13 14 15

Program 2: Adding String in the queue.




/* Java Program Demonstrate put()
method of LinkedTransferQueue */
  
import java.util.concurrent.*;
  
class LinkedTransferQueuePutExample2 {
    public static void main(String[] args)
    {
        // Initializing the queue
        LinkedTransferQueue<String> queue = 
                     new LinkedTransferQueue<String>();
  
        // Adding elements to this queue
        queue.put("alex");
        queue.put("bob");
        queue.put("chuck");
        queue.put("drake");
        queue.put("erick");
  
        // Printing the elements of the queue
        System.out.println("The elements in the queue are:");
        for (String i : queue)
            System.out.print(i + " ");
    }
}


Output:

The elements in the queue are:
alex bob chuck drake erick

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedTransferQueue.html#put(E)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS