Tech Master Tutorials
Email Facebook Google LinkedIn Pinterest Twitter
Home Java Java 8 Java Interview Questions Java8 Interview Questions Object Oriented Programming in Java JVM Java Programming

HashSet

Internal Implementation details of HashSet:

HashSet internally uses a HashMap to store the values.

HashMap contains all the keys unique and if anyone tries to insert a value with some key that is already existing then it updates the value corresponding to the already existing key.

HashSet uses the unique key concept of the HasMap and inserts the values of the HashSet in the underlying HashMap as keys and just put some dummy object corresponding to each key. Which makes it a O(1) insertion data structure and keeps the values unique in a HashSet.

To know the HashMap and internal working of HashMap go to the link :HashMap