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.indexOf() in Java
- Java.util.ArrayList.add() Method in Java
- Get first and last elements from ArrayList in Java
- ArrayList trimToSize() in Java with example
- Initialize an ArrayList in Java
- Reverse an ArrayList in Java
- How to get ArrayList from Stream in Java 8
- 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 firstname.lastname@example.org. 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.