ConcurrentLinkedQueue size() method in Java Last Updated : 26 Nov, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The size() method of ConcurrentLinkedQueue is used to returns number of elements that this ConcurrentLinkedQueue contains. Syntax: public int size() Returns: This method number of elements in this ConcurrentLinkedQueue. Below programs illustrate size() method of ConcurrentLinkedQueue: Example 1: Java // Java Program Demonstrate size() // method of ConcurrentLinkedQueue import java.util.concurrent.*; public class GFG { public static void main(String[] args) { // create an ConcurrentLinkedQueue ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<Integer>(); // Add Numbers to queue queue.add(4353); queue.add(7824); queue.add(78249); queue.add(8724); // Displaying the existing ConcurrentLinkedQueue System.out.println("ConcurrentLinkedQueue: " + queue); // apply size() int size = queue.size(); // print after applying size method System.out.println("Size of ConcurrentLinkedQueue: " + size); } } Output: ConcurrentLinkedQueue: [4353, 7824, 78249, 8724] Size of ConcurrentLinkedQueue: 4 Example 2: Java // Java Program Demonstrate size() // method of ConcurrentLinkedQueue import java.util.concurrent.*; public class GFG { public static void main(String[] args) { // create an ConcurrentLinkedQueue ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>(); // Add String to queue queue.add("Aman"); queue.add("Amar"); queue.add("Sanjeet"); queue.add("Rabi"); // Displaying the existing ConcurrentLinkedQueue System.out.println("ConcurrentLinkedQueue: " + queue); // apply size() on queue int size = queue.size(); // print after applying size method System.out.println("Size of ConcurrentLinkedQueue: " + size); // removal of some elements queue.poll(); queue.poll(); // get size of ConcurrentLinkedQueue again size = queue.size(); // Displaying the existing ConcurrentLinkedQueue System.out.println("After 2 removal of elements\n" + "ConcurrentLinkedQueue: " + queue); // print after applying size method System.out.println("Size of ConcurrentLinkedQueue: " + size); } } Output: ConcurrentLinkedQueue: [Aman, Amar, Sanjeet, Rabi] Size of ConcurrentLinkedQueue: 4 After 2 removal of elements ConcurrentLinkedQueue: [Sanjeet, Rabi] Size of ConcurrentLinkedQueue: 2 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html#size-- Comment More infoAdvertise with us Next Article ConcurrentLinkedQueue remove() method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Collections Java - util package java-basics Java-Functions Java-ConcurrentLinkedQueue +2 More Practice Tags : JavaJava-Collections Similar Reads ConcurrentLinkedDeque size() method in Java The size() method of ConcurrentLinkedDeque class in Java is used to find the number of elements present in the ConcurrentLinkedDeque container. In other words, this method tells the current capacity of the container. The value returned by this method is of integral type and in case if the container 2 min read ConcurrentLinkedQueue peek() method in Java The peek() method of ConcurrentLinkedQueue is used to return the head of the ConcurrentLinkedQueue. It retrieves but does not remove, the head of this ConcurrentLinkedQueue. If the ConcurrentLinkedQueue is empty then this method returns null. Syntax: public E peek() Returns: This method returns the 2 min read ConcurrentLinkedQueue offer() method in Java The offer() method of ConcurrentLinkedQueue is used to insert the element, passed as parameter, at the tail of this ConcurrentLinkedQueue. This method returns True if insertion is successful. ConcurrentLinkedQueue is unbounded, so this method offer() will never returns false. Syntax: public boolean 2 min read ConcurrentLinkedQueue remove() method in Java The remove(Object o) method of ConcurrentLinkedQueue is used to remove a single instance of the specified element from this ConcurrentLinkedQueue, if it is present. This method removes an element e such that o.equals(e) if this ConcurrentLinkedQueue contains one or more such elements. Remove() metho 2 min read ConcurrentLinkedQueue spliterator() method in Java The spliterator() method of ConcurrentLinkedQueue is used to get a Spliterator of the same elements as ConcurrentLinkedQueue. Created Spliterator is weakly consistent. It can be used with Streams in Java 8. Also it can traverse elements individually and in bulk too. Spliterator is better way to trav 2 min read ConcurrentLinkedQueue poll() method in Java The poll() method of ConcurrentLinkedQueue is used to remove and return the head of this ConcurrentLinkedQueue. If the ConcurrentLinkedQueue is empty then this method will return null. Syntax: public E poll() Returns: This method remove and returns the head of this ConcurrentLinkedQueue or null if t 2 min read Like