Remove all elements from Java HashSet
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());
}
}
/*
[1, 2, 3]
[]
true
*/
Related examples in the same category