BlockingDeque size() method in Java with Examples Last Updated : 14 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The size() method of BlockingDeque returns the current size of the Deque container. On calling the function the number of elements in the Deque container is returned. If the container is capacity restricted, then also it returns the number of elements which are present in the container at the time of function call. Syntax: public int size() Returns: This method returns an integer value which signifies the number of elements in the container. Note: The size() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java. Below programs illustrate size() method of BlockingDeque: Program 1: Java // Java Program to demonstrate public int size() // method of BlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of BlockingDeque BlockingDeque<Integer> BD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of BlockingDeque BD.add(15); BD.add(20); BD.add(20); BD.add(15); BD.add(15); BD.add(20); BD.add(20); BD.add(15); // print Deque System.out.println("Blocking Deque: " + BD); // prints the Deque after removal System.out.println("Size of Blocking Deque: " + BD.size()); } } Output: Blocking Deque: [15, 20, 20, 15, 15, 20, 20, 15] Size of Blocking Deque: 8 Program 2: Java // Java Program to demonstrate public int size() // method of BlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of BlockingDeque BlockingDeque<String> BD = new LinkedBlockingDeque<String>(); // Add numbers to end of BlockingDeque BD.add("geeks"); BD.add("forGeeks"); BD.add("A Computer"); BD.add("Portal"); // print Dequeue System.out.println("Blocking Deque: " + BD); // prints the Deque after removal System.out.println("Size of Blocking Deque: " + BD.size()); } } Output: Blocking Deque: [geeks, forGeeks, A Computer, Portal] Size of Blocking Deque: 4 Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingDeque.html#size() Comment More infoAdvertise with us Next Article BlockingDeque peek() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java - util package Java-Functions Java-BlockingDeque Practice Tags : Java Similar Reads BlockingDeque push() method in Java with examples The push(E e) method of BlockingDeque pushes an element onto the stack represented by this deque. It inserts the element passed in the parameter to the front of the Deque if there is space. If the BlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateExce 2 min read BlockingDeque push() method in Java with examples The push(E e) method of BlockingDeque pushes an element onto the stack represented by this deque. It inserts the element passed in the parameter to the front of the Deque if there is space. If the BlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateExce 2 min read BlockingDeque peek() method in Java with examples The peek() method of BlockingDeque returns the front element in the Deque container. It returns null if the container is empty. Syntax: public E peek() Parameters: This method does not accept any parameters. Returns: This method returns front element in the Deque container if the container is not em 2 min read BlockingDeque peek() method in Java with examples The peek() method of BlockingDeque returns the front element in the Deque container. It returns null if the container is empty. Syntax: public E peek() Parameters: This method does not accept any parameters. Returns: This method returns front element in the Deque container if the container is not em 2 min read BlockingDeque take() method in Java with Examples The take() method of BlockingDeque returns and removes the head of the Deque container from it. The method throws an InterruptedException if it is interrupted while waiting. Syntax: public E take() Returns: This method returns the head of the Deque container. Exception: The function throws a Interru 2 min read BlockingDeque put() method in Java with Examples The put(E e) method of BlockingDeque inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque). If the Deque is capacity restricted, then it will wait for the space to become available. Syntax: public void put(E e) Parameters: This method acce 2 min read Like