VOOZH about

URL: https://www.geeksforgeeks.org/java/arraylist-size-method-in-java-with-examples/

⇱ ArrayList size() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ArrayList size() Method in Java with Examples

Last Updated : 11 Jul, 2025

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.


Output
3

Syntax of ArrayList size() Method

public 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.


Output
3


Example 3: Here, we demonstrate how to use the size() method on an ArrayList that stores objects.


Output
2
Comment