Java : HashSet

Posted in Java Collections By Raj On November 18, 2017


HashSet extends AbstractSet and implements the Set interface. Internally the HashSet create a collection which uses hash table for storage,  the hash table uses hashing mechanism to store data, the below things you should consider if you are planning to use HashSet

  • The HashSet will not allow duplicate values it won’t give any error while adding instead of error it will just return boolean values
  • There is no guarantee that whatever order you have stored you will get it

Output :