Size of HashSet can be find by size() method. In size method, it will return value in integer.
Example of finding size in HashSet in Java
HashSet<String> hs=new HashSet<String>();
hs.add("b");
hs.add("a");
hs.add("c");
hs.add("d");
hs.add("d");
int sizeOfHashSet=hs.size();
System.out.println("Size of HashSet :"+sizeOfHashSet);
Output
Size of HashSet :4
Tags: Collections



Link to Us