In this shot, we will discuss the Deque.size()
method in Java, which is present in the Deque
interface inside the java.util
package.
The Deque.size()
method is used to obtain the number of elements present in the deque.
x size()
The Deque.size()
method doesn’t take any parameters.
The Deque.size()
method returns size
, which is the number of elements present in the Deque
.
Let’s look at the code snippet below.
import java.util.*;class Main{public static void main(String[] args){Deque<Integer> d = new LinkedList<Integer>();//Adding elementsd.add(212);d.add(621);d.add(23);d.add(1280);d.add(1171);System.out.println("Elements in the deque are: "+d);//Displaying the size of dequeSystem.out.println("Number of elements in the deque are: "+d.size());}}
Main
class.main
function.Deque
consisting of Integer
type elements.Deque.add()
method.Deque.size()
method and displayed the number of elements present in the deque.In this way, we can use the Deque.size()
method in Java.