Example
Determine 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 reveals the number of elements present in the list.
Syntax
Technical Details
|
Returns:
|
The count of elements within the list.
|