Java developer interview questions shared by candidates
What are they things you need to look at when you make an object as key of a Map
A map cannot contain duplicate keys; each key can map to at most one value. some implementations prohibit null keys and values, and some have restrictions on the types of their keys. Hash map allows null keys.
You missed the most important part. You should make sure that your key object's hash value is always consistent even if you change some of its property. If the hash value changes, then you'll be looking under wrong bucket for the value and never find any.
You need to make sure equals() and hashcode() are consistent, ie for two objects that are equal the hash code is the same and vice versa.
See Interview Questions for Similar Jobs
- Senior Java Developer
- Software Engineer
- Software Developer
- Senior Software Engineer
- Senior Developer
- Analyst Programmer
- Senior Software Developer
- Program Manager
- Senior Manager
- Web Developer