Movatterモバイル変換


[0]ホーム

URL:


Open In App
The Java.util.ArrayDeque.size() method in Java is used to get the size of the Deque or the number of elements present in the Deque.Syntax:
Array_Deque.size()
Parameters: The method does not take any parameter.Return Value: The method returns the size or the number of elements present in the Deque.Below programs illustrate the Java.util.ArrayDeque.size() method:Program 1: Adding String elements into the Deque.Java
// Java code to illustrate size()importjava.util.*;publicclassArrayDequeDemo{publicstaticvoidmain(Stringargs[]){// Creating an empty ArrayDequeDeque<String>de_que=newArrayDeque<String>();// Use add() method to add elements into the Dequede_que.add("Welcome");de_que.add("To");de_que.add("Geeks");de_que.add("4");de_que.add("Geeks");// Displaying the ArrayDequeSystem.out.println("ArrayDeque: "+de_que);// Displaying the size of DequeSystem.out.println("The size is: "+de_que.size());}}
Output:
ArrayDeque: [Welcome, To, Geeks, 4, Geeks]The size is: 5
Program 2: Adding Integer elements into the Deque.Java
// Java code to illustrate clear()importjava.util.*;publicclassArrayDequeDemo{publicstaticvoidmain(Stringargs[]){// Creating an empty ArrayDequeDeque<Integer>de_que=newArrayDeque<Integer>();// Use add() method to add elements into the Dequede_que.add(10);de_que.add(15);de_que.add(30);// Displaying the ArrayDequeSystem.out.println("ArrayDeque: "+de_que);// Displaying the size of DequeSystem.out.println("The size is: "+de_que.size());}}
Output:
ArrayDeque: [10, 15, 30]The size is: 3

Improve

Explore

Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp