Discussion
Which of these statements about using a mutable object as a HashMap key and then changing it is correct?
Answer: D
A hash table finds a bucket from the key's hash code and only then compares with equals. If the field that hashCode depends on is changed after insertion, a later lookup computes a different bucket and finds nothing, while the entry still occupies the old one. Keys should be immutable, or at least stable in the fields hashCode reads.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development