Remove all elements from ArrayList in Java
Description
The following code shows how to remove all elements from ArrayList.
Example
//from w ww.j av a2 s. c o m
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("java2s.com");
System.out.println(arrayList.size());
arrayList.clear();
System.out.println(arrayList.size());
}
}
The code above generates the following result.