Is it possible to store multiple values under the same key?


#1

Question

In the context of this exercise, is it possible to store multiple values under the same key?

Answer

No, this is not possible because keys are unique, and there can only be one key-value pair for each key.

For instance, say that we could actually have multiple values stored under the same key:
hash_map[4] is val1
and
hash_map[4] is val2

This is not possible, because an index cannot store two values simultaneously. One of the values had to have overwritten the other when adding them to the hash map.