Given an ArrayList in Java, the task is to find the length or size of the ArrayList.
Input: ArrayList: [1, 2, 3, 4, 5] Output: 5 Input: ArrayList: [geeks, for, geeks] Output: 3
The size of the ArrayList can be determined easily with the help of size() method. This method does not take any parameters and returns an integer value which is the size of the ArrayList.
int size = ArrayList.size();
Below is the implementation of the above approach:
ArrayList: [1, 2, 3, 4, 5] Size of ArrayList = 5
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Difference between length of Array and size of ArrayList in Java
- ArrayList size() method in Java with Examples
- Find first and last element of ArrayList in java
- How to determine length or size of a String in Java?
- How to determine length or size of an Array in Java?
- ArrayList of ArrayList in Java
- Java.util.ArrayList.addall() method in Java
- Java.util.Arraylist.indexOf() in Java
- Java.util.ArrayList.add() Method in Java
- Arraylist.contains() in Java
- ArrayList in Java
- How to get ArrayList from Stream in Java 8
- Array of ArrayList in Java
- Arraylist lastIndexOf() in Java with example
- Array vs ArrayList in Java
- Get first and last elements from ArrayList in Java
- Custom ArrayList in Java
- ArrayList vs. HashMap in Java
- ArrayList vs LinkedList in Java
- ArrayList isEmpty() in Java with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.