Javatpoint Logo
Javatpoint Logo

Java ConcurrentLinkedQueue size() method

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

Syntax:

Parameters:

NA

Specified By:

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

size() method in interface Collection<E>.

Return Value:

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

Example 1

Test it Now

Output:

The size of queue : 4
Queue : [12, 67, 45, 123]

Example 2

Test it Now

Output:

Total Patients = 6
1.Megha
2.Reema
3.Supriya
4.Anoop
5.Sonia
6.Tejashvi
Patients recovered and discharged : [Megha, Reema, Supriya, Anoop]
Patients left in the hospital = 2
1.Sonia
2.Tejashvi

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.NullPointerException
	at java.util.concurrent.ConcurrentLinkedQueue.checkNotNull(ConcurrentLinkedQueue.java:920)
	at java.util.concurrent.ConcurrentLinkedQueue.offer(ConcurrentLinkedQueue.java:327)
	at java.util.concurrent.ConcurrentLinkedQueue.add(ConcurrentLinkedQueue.java:297)
	at com.javaTpoint.ConcurrentLinkedQueueSizeExample3.main(ConcurrentLinkedQueueSizeExample3.java:7)






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA