I attended an interview and was asked this question.
There are two objects with the same hashcode. I am inserting these two objects inside a hashmap.
Now tell me how many objects will be there inside the hashmap?
I answered there will be only one object since the hashcodes are equal the two objects will be equal and hashmap will not allow duplicate keys. Please tell me whether my understanding is correct or not?
There are two objects with the same hashcode. I am inserting these two objects inside a hashmap.
Codice:
hMap.put(a,a);
hMap.put(b,b);
where a.hashCode()==b.hashCode()
Now tell me how many objects will be there inside the hashmap?
I answered there will be only one object since the hashcodes are equal the two objects will be equal and hashmap will not allow duplicate keys. Please tell me whether my understanding is correct or not?