Wednesday, 4 June 2014

Difference between hashSet and hashMap

  1. HashSet is an implementation of Set Interface. HashMap is a implementation of Map interface
  2. HashSet stores Objects. HashMap stores data in <Key,Value> pair format.
  3. HashSet uses add method to add elements to HashSet, where as HashMap uses put method, which takes two arguments key, value.
  4. HashSet internally uses HashMap to store data.
  5. In case of the HashSet, adding the same object do nothing. In case of a HashMap, putting a new key,value pair with an existing key will overwrite the existing value to set a new value for that key.
  6. HashSet contains unique Keys. HashMap contains unique keys and allow duplicate values.

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment