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
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.