SpinTheMic
Pro

Interview practice question

Objects disappear from a HashMap

Backend Engineering · Language Runtimes · Beginner

You put an object into a HashSet, changed one of its fields, and now contains() returns false for it. Why?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • hashCode depends on mutable field.
  • Object now in wrong bucket.
  • Never mutate keys in hash collections.
  • Use immutable keys/IDs.
  • Or remove, modify, re-insert.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics