![]() |
VOOZH | about |
In Java, the size() method is used to get the number of elements in an ArrayList.
Example 1: Here, we will use the size() method to get the number of elements in an ArrayList of integers.
3
size() Methodpublic int size()
Returns Value: This method returns the number of elements in the list.
Example 2: Here, we use the size() method to get the number of elements in an ArrayList of strings.
3
Example 3: Here, we demonstrate how to use the size() method on an ArrayList that stores objects.
2