Get Size of HashSet in Java
Description
The following code shows how to get Size of HashSet.
Example
/*from w ww .jav a 2 s .co m*/
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
HashSet<Integer> hSet = new HashSet<Integer>();
System.out.println("Size of HashSet : " + hSet.size());
hSet.add(new Integer("1"));
hSet.add(new Integer("2"));
hSet.add(new Integer("3"));
System.out.println(hSet.size());
hSet.remove(new Integer("1"));
System.out.println(hSet.size());
}
}
The code above generates the following result.