The size() method returns the number of elements present in the arraylist.
Example
Syntax of ArrayList size()
The syntax of the size() method is:
arraylist.size()
Here, arraylist is an object of the ArrayList class.
size() Parameters
The size() method does not take any parameters.
size() Return Value
- returns the number of elements present in the arraylist.
Example: Get the Length of an ArrayList
Output
ArrayList: [JavaScript, Java, Python] Length of ArrayList: 3
In the above example, we have created an arraylist named languages. Here, we have used the size() method to get the number of elements present in the arraylist.