LinkedBlockingDeque size() method in Java
The size() method of LinkedBlockingDeque 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.
Below programs illustrate size() method of LinkedBlockingDeque:
Program 1:
// Java Program to demonstrate public int size() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.add(15); LBD.add(20); LBD.add(20); LBD.add(15); LBD.add(15); LBD.add(20); LBD.add(20); LBD.add(15); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); // prints the Deque after removal System.out.println("Size of Linked Blocking Deque: " + LBD.size()); } } |
Linked Blocking Deque: [15, 20, 20, 15, 15, 20, 20, 15] Size of Linked Blocking Deque: 8
Program 2:
// Java Program to demonstrate public int size() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of LinkedBlockingDeque LinkedBlockingDeque<String> LBD = new LinkedBlockingDeque<String>(); // Add numbers to end of LinkedBlockingDeque LBD.add("geeks"); LBD.add("forGeeks"); LBD.add("A Computer"); LBD.add("Portal"); // print Dequeue System.out.println("Linked Blocking Deque: " + LBD); // prints the Deque after removal System.out.println("Size of Linked Blocking Deque: " + LBD.size()); } } |
Linked Blocking Deque: [geeks, forGeeks, A Computer, Portal] Size of Linked Blocking Deque: 4
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#size–
Recommended Posts:
- LinkedBlockingDeque add() method in Java
- LinkedBlockingDeque take() method in Java
- LinkedBlockingDeque contains() method in Java
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque put() method in Java
- LinkedBlockingDeque removeLastOccurrence() method in Java
- LinkedBlockingDeque getLast() method in Java
- LinkedBlockingDeque poll() method in Java
- LinkedBlockingDeque peekLast() method in Java
- LinkedBlockingDeque removeLast() method in Java
- LinkedBlockingDeque descendingIterator() method in Java
- LinkedBlockingDeque peekFirst() method in Java
- LinkedBlockingDeque pollLast() method in Java
- LinkedBlockingDeque drainTo() method in Java with Example
- LinkedBlockingDeque peek() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



