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:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
LBD.add( 15 );
LBD.add( 20 );
LBD.add( 20 );
LBD.add( 15 );
LBD.add( 15 );
LBD.add( 20 );
LBD.add( 20 );
LBD.add( 15 );
System.out.println( "Linked Blocking Deque: " + LBD);
System.out.println( "Size of Linked Blocking Deque: "
+ LBD.size());
}
}
|
Output:
Linked Blocking Deque: [15, 20, 20, 15, 15, 20, 20, 15]
Size of Linked Blocking Deque: 8
Program 2:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
LinkedBlockingDeque<String> LBD
= new LinkedBlockingDeque<String>();
LBD.add( "geeks" );
LBD.add( "forGeeks" );
LBD.add( "A Computer" );
LBD.add( "Portal" );
System.out.println( "Linked Blocking Deque: " + LBD);
System.out.println( "Size of Linked Blocking Deque: "
+ LBD.size());
}
}
|
Output:
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–
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
26 Nov, 2018
Like Article
Save Article