If I have to know the key to get the value in a hashmap (for time complexity O(1)), why is it any different than getting a value inside an array when knowing the index (O(1) as well)?
In other words, a hashmap is considered having O(1) complexity for a lookup, but this is because the key is known. This is the same with an array when the index is known--if I don't know the index it would be O(n) which is the same as not knowing the key and then it's O(n) for the hashmap as well (containsValue(Object value) method).
Therefore, I don't understand why a hashmap is considered to be more efficient for lookups.