In this example we will show the method to remove all items from an ArrayList in Java.
Source Code
package com.beginner.examples;
import java.util.ArrayList;
public class ClearArrayList {
public static void main(String[] args) {
ArrayList strs = new ArrayList();
strs.add("a");
strs.add("b");
strs.add("c");
strs.clear(); // remove all items
System.out.println(strs);
}
}
Output:
[]
References
Imported packages in Java documentation: