Example & Tutorial understanding programming in easy ways.

What is difference between HashMap and HashSet?

The difference between HashMap and HashSet are following:-

                           HashMap                              HashSet
1 HashMap is a implementation of Map interface. 1 HashSet is an implementation of Set Interface.
2 HashMap Stores data in form of key and pair. 2 HashSet Store data in form of objects.
3 To add elements put() methods is used. 3 To add element add() methods is used.
4 In HashMap hashcode value is calculated using key object. 4 Member object is used for calculating hashcode value. Two object may have same hash code.
5 HashMap is faster than hashSet because unique key is used to access object. 5 HashSet is slower than HashMap.

Read More →