NetApp Interview Question
AnalystsTeam: Bigdata analyst
Country: India
Interview Type: In-Person
HashMap's put() and get() methods utilize the hashCode() and equals() function. Note that 'abc' and 'ABC' are distinct separate values. As such, the hashCode(abc) and hashCode(ABC) will result in different key values.
On the other side, let's say that we have a key collision and we're trying to retrieve a case sensitive value from the resulting LinkList that is created at that bucket entry. Then the .equals(abc) and .equals(ABC) can clearly distinguish what value you are seeking.
The question does not make sense if the point is to have "abc" and "ABC" mapped to different hash values. It already does that by default.
- Miguel Oliveira August 31, 2013If the point was to consider "abc" and "ABC" as the same key, we would have to override the hashCode() and equal() of the type we're putting in the HashMap.
This would make more sense as an interview question.