What does Java use to determine whether keys in a map are duplicated?
My first instinct is that every key is an object and has a hash code, which is used to determine whether to insert a duplicate But I can't find anything Can anyone provide a link or provide a real answer? thank you!
Solution
The map interface specifies that if two keys are empty, they are duplicate; otherwise, if there is a key The key K of equals (k) is duplicated See the include or get method here:
http://java.sun.com/javase/6/docs/api/java/util/Map.html#containsKey (java.lang.Object)
However, how to perform this check is performed by map, and HashMap will use hash code to reduce the potential key checked by equals method Therefore, in practice, for a typical hash based map, in order to check the duplicate map, the map will use hash code (some size may be modulated), and use equals to compare any key with the same size as its hash code mode and give the same remainder