Hashset V/s HashMap

Collections

Hashset
In hashset, one can store values or objects such as { obj1, obj2, obj3, obj4 }
It doesn't allow duplicate elements. Hashset is the implementation of set interface whereas HashMap implements the Map interface.HashMap
In HashMap, one can store key, value pair such as {1>”Apple”, 2>”Mango”,3>”Banana” }
HashMap does not allow duplicate keys whereas it allows to have duplicate values and HashMap implements the Map interface.

Both HashMap and HashSet are not synchronized. HashSet is slower that HashMap because HashMap internally uses hashing to store or add objects and HashSet internally uses HashMap object to store or add the objects.

 •  0 comments  •  flag
Share on Twitter
Published on March 25, 2019 05:41
No comments have been added yet.