Java ArrayList clear() Method
Example
Remove all items from 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");
cars.clear();
System.out.println(cars);
}
}
Definition and Usage
The clear()
removes all items from the list.
Syntax
public void clear()
Related Pages
❮ ArrayList Methods