Java ConcurrentLinkedQueue size() methodThe 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 1Output: The size of queue : 4 Queue : [12, 67, 45, 123] Example 2Output: 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 3Output: 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) |