Alex Rivera | Logout

What does Java use to determine if a key is a duplicate in a Map?

Asked 2008-12-13T03:51:53.250
12

My first instinct is to say each key is an object, and has a hash code, which is what is used to determine if a duplicate is being inserted. However, I can't find anything to back that up for sure. Can someone provide a link that says that, or provide the real answer here? Thanks!

Edit
Report

1 Answer

1

It uses the equals() method on the key. The hashCode() method just helps efficiently store the keys for the map.

answered 2008-12-13T03:55:06.037

Your Answer