Example
Empty the list by removing all of its items.
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"); cars.clear(); System.out.println(cars);
}
}
|
Definition and Usage
The clear() method removes all items from the list.
Syntax