- Java
- Collections Data Structure
- HashSet
Get Size of Java HashSet
import java.util.HashSet; publicclass Main { publicstaticvoid main(String[] args) { HashSet<Integer> hSet = new HashSet<Integer>(); System.out.println("Size of HashSet : " + hSet.size()); hSet.add(newInteger("1")); hSet.add(newInteger("2")); hSet.add(newInteger("3")); System.out.println(hSet.size()); hSet.remove(newInteger("1")); System.out.println(hSet.size()); } } /* Size of HashSet : 0 3 2 */
Related examples in the same category