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
- How to determine length or size of an Array in Java?
- How to determine length or size of a String in Java?
- Find first and last element of ArrayList in java
- ArrayList of ArrayList in Java
- Java.util.ArrayList.addall() method in Java
- Arraylist.contains() in Java
- ArrayList in Java
- Java.util.ArrayList.add() Method in Java
- Java.util.Arraylist.indexOf() in Java
- ArrayList vs. HashMap in Java
- How to get ArrayList from Stream in Java 8
- ArrayList trimToSize() in Java with example
- 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.