Java ArrayList size() Method
Example
Find out the size of a list:
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> cars = new ArrayList<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println(cars.size());
}
}
Definition and Usage
The size()
method indicates how many elements are in the list.
Syntax
public int size()
Technical Details
Returns: | The number of elements in the list. |
---|
Related Pages
❮ ArrayList Methods