Java LinkedTransferQueue size() method

The size() method of LinkedTransferQueue class returns the returns the total count of the elements present in the queue.

Syntax:

Specified By:

The size() method of LinkedTransferQueue class is specified by:

  • size in interface Collection
  • size in class AbstractCollection

Return:

This method returns the number of elements in this queue.

Example 1

Test it Now

Output:

The size of queue : 4
Queue : [34, 22, 26, 215]

Example 2

Test it Now

Output:

Total Patients = 6
1.John
2.Harry
3.Peter
4.Marry
5.Jack
6.Lucene
Patients recovered and discharged : [John, Harry, Peter, Marry]
Patients left in the hospital = 2
1.Jack
2.Lucene

Example 3

Test it Now

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.add(Unknown Source)
	at tests.LinkedTransferQueueSizeExample3.main(LinkedTransferQueueSizeExample3.java:5)





Latest Courses