Remove all elements from HashSet in Java
Description
The following code shows how to remove all elements from HashSet.
Example
/*from w w w .jav a 2 s .c om*/
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
HashSet<Integer> hSet = new HashSet<Integer>();
hSet.add(new Integer("1"));
hSet.add(new Integer("2"));
hSet.add(new Integer("3"));
System.out.println(hSet);
hSet.clear();
System.out.println(hSet);
System.out.println(hSet.isEmpty());
}
}
The code above generates the following result.