Java HashSet Size Example
Chapter:
Collections
Last Updated:
10-05-2016 19:50:23 UTC
Program:
/* ............... START ............... */
import java.util.HashSet;
public class JavaHashSetSizeExample {
public static void main(String[] args) {
//create HashSet object
HashSet hashSet = new HashSet();
System.out.println("Size of HashSet : " + hashSet.size());
hashSet.add(new Integer("1"));
hashSet.add(new Integer("2"));
hashSet.add(new Integer("3"));
System.out.println("Size of HashSet after addition : " + hashSet.size());
hashSet.remove(new Integer("1"));
System.out.println("Size of HashSet after removal : " + hashSet.size());
}
}
/* ............... END ............... */
Output
Size of HashSet : 0
Size of HashSet after addition : 3
Size of HashSet after removal : 2
Tags
Collection, HashSet Size, Java