Sunday, September 25, 2016

HashSet Internals

Experimenting how to use Objects as elements in HashSet.
The code below explores how hashCode() and equals() functions are used in HashSet and how to override them so that you can tweak it for your own needs.

Comments contain the explanation and check the output to see when hashCode() and equals() functions are called.



The image below shows the map variable expanded.
Explanation why values have the same Object id : stackoverflow