Remove all elements from Java HashSet
import java.util.HashSet; publicclass Main { publicstaticvoid main(String[] args) { HashSet<Integer> hSet = new HashSet<Integer>(); hSet.add(newInteger("1")); hSet.add(newInteger("2")); hSet.add(newInteger("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