Java examples for Collection Framework:HashSet
Get Size of HashSet
import java.util.HashSet; public class Main { public static void main(String[] args) { HashSet hSet = new HashSet(); System.out.println("Size of HashSet : " + hSet.size()); /*from w w w . j a v a 2s . c o m*/ //add elements to HashSet object hSet.add(new Integer("1")); hSet.add(new Integer("2")); hSet.add(new Integer("3")); System.out.println("Size of HashSet after addition : " + hSet.size()); //remove one element from HashSet using remove method hSet.remove(new Integer("1")); System.out.println("Size of HashSet after removal : " + hSet.size()); } }