Java LinkedList size() Method
Example
Find out the size of a list:
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<String> cars = new LinkedList<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
❮ LinkedList Methods