Friday, October 24, 2025
HomeLanguagesJavaBlockingDeque size() method in Java with Examples

BlockingDeque size() method in Java with Examples

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 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 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()

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS