Java ArrayDeque - size() Method
The java.util.ArrayDeque.size() method returns the number of elements in the deque.
Syntax
public int size()
Parameters
No parameter is required.
Return Value
Returns the number of elements in the deque.
Exception
NA
Example:
In the example below, the java.util.ArrayDeque.size() method is used to find out the number of elements in the given deque.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a ArrayDeque ArrayDeque<Integer> MyDeque = new ArrayDeque<Integer>(); //populating ArrayDeque MyDeque.add(10); MyDeque.add(20); MyDeque.add(30); System.out.println("Size of MyDeque: " + MyDeque.size()); //adding one more element in the ArrayDeque MyDeque.add(40); System.out.println("One element is added in the MyDeque."); System.out.println("Now, Size of MyDeque: " + MyDeque.size()); } }
The output of the above code will be:
Size of MyDeque: 3 One element is added in the MyDeque. Now, Size of MyDeque: 4
❮ Java.util - ArrayDeque