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
- 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
- ArrayList of ArrayList in Java
- Java.util.ArrayList.addall() method in Java
- ArrayList in Java
- Arraylist.contains() in Java
- Java.util.ArrayList.add() Method in Java
- Java.util.Arraylist.indexOf() in Java
- Array of ArrayList in Java
- Arraylist lastIndexOf() in Java with example
- Reverse an ArrayList in Java
- How to get ArrayList from Stream in Java 8
- ArrayList vs. HashMap in Java
- Vector vs ArrayList in Java
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.