Friday, July 10, 2026
HomeLanguagesJavaLinkedTransferQueue size() method in Java

LinkedTransferQueue size() method in Java

The java.util.concurrent.LinkedTransferQueue.size() method is an in-built function in Java which gives the total count of the elements present in the queue.

Syntax:

LinkedTransferQueue.size()

Parameters: The function does not accept any parameter.

Return Value: The function returns the number of elements in the queue.

Below programs illustrate the LinkedTransferQueue.size() method:

Program 1:




// Java Program Demonstrate size()
// method of LinkedTransferQueue 
  
import java.util.concurrent.LinkedTransferQueue;
  
class LinkedTransferQueueSizeExample1 {
    public static void main(String[] args)
    {
        // Initializing the queue
        LinkedTransferQueue<Integer> queue =
                      new LinkedTransferQueue<Integer>();
  
        // Adding elements to this queue
        for (int i = 1; i <= 10; i++)
            queue.add(i);
  
        // Printing the size of the queue
        System.out.println("Number of elements in the queue = " 
                                                + queue.size());
        // Printing the elements
        System.out.println("Queue : " + queue);
    }
}


Output:

Number of elements in the queue = 10
Queue : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Program 2:




// Java Program Demonstrate size()
// method of LinkedTransferQueue 
  
import java.util.concurrent.LinkedTransferQueue;
  
class LinkedTransferQueueSizeExample2 {
    public static void main(String[] args)
    {
        // Initializing the queue
        LinkedTransferQueue<String> queue = 
                  new LinkedTransferQueue<String>();
  
        // Adding elements to this queue
        queue.add("A");
        queue.add("B");
        queue.add("C");
        queue.add("D");
        queue.add("E");
  
        // Printing the size of the queue
        System.out.println("Number of elements in the queue = " 
                                                + queue.size());
        // Printing the elements
        System.out.println("Queue : " + queue);
    }
}


Output:

Number of elements in the queue = 5
Queue : [A, B, C, D, E]

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6901 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12111 POSTS0 COMMENTS
Shaida Kate Naidoo
7021 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6978 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS