Note : HashSet internally uses hash maps to store the values.
When set values are inserted using HashSet, does it store it as keys or values in hashmap internally?
it stores as keys, as keys can't be duplicate values
it stores as values, as values can't be duplicate values
it can be either of option1 or 2 depends.
1.Hashset internally uses hash maps to store its values.
Hash map basic property says keys can't be duplicated, but values can be duplicated.
2.In HashSet we know that, it will not accept duplicate values.
Based on above two statements, it is obvious that Hashset stores the set values as keys in the hash map internal implementation.
Back To Top