Determine the size of a list.
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
args
LinkedList<String> cars = new LinkedList<String>();
cars
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println(cars.size());
out
}
Definition and Usage
The size() method denotes the number of elements present in the list.
Syntax
public int size()
Technical Details
Returns:
The count of elements within the list.