???????Java??????????HashMap??????????????????????Hashmap??

????????HashMap??????????????????????????HashMap???????????????????HashMap????????????????????????HashMap???????????????????????????????javadoc.

????κ??????????????HashMap????????????????????“????Hash?????”????仰?????????????????仰???????????????????????????????

??????

??????????????/???????????????????????????????????????????????/????????????????????????????????????

?????????????????????????equal??????????????ж???÷??????????????仰????????????????????????hashcode??

???????Java??????Object?????????????hashCode()?????????????????????????е??????????????????????????hash????????????????????в????hashcode??

????Entry?????????

???map?????????????????key???????value??????????????ɡ?

???????HashMap??????????????????洢??Щ??????????HashMap??????????Entry????????????????

 

    static class Entry<K??V> implements Map.Entry<K??V>  
    { 
            final K key; 
            V value; 
            Entry<K??V> next; 
            final int hash; 
            ...//More code goes here 
    }

?????Entry?????????????洢????????key??final????????key??value????????????????????next??hash?????????????????????Щ????????塣

put()???????????????

????????put??????????????????б???????Entry??????????е?洢??HashMap??????????????

    /** 
         * The table?? resized as necessary. Length MUST Always be a power of two. 
         */
        transient Entry[] table;

??????????put??????????

    /** 
    * Associates the specified value with the specified key in this map. 
    * If the map previously contained a mapping for the key?? the old 
    * value is replaced. 
    * 
    * @param key key with which the specified value is to be associated 
    * @param value value to be associated with the specified key 
    * @return the previous value associated with <tt>key</tt>?? or 
    *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <tt>null</tt> if there was no mapping for <tt>key</tt>. 
    *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (A <tt>null</tt> return can also indicate that the map 
    *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; previously associated <tt>null</tt> with <tt>key</tt>.) 
    */
    public V put(K key?? V value) { 
    if (key == null) 
    return putForNullKey(value); 
    int hash = hash(key.hashCode()); 
    int i = indexFor(hash?? table.length); 
    for (Entry<K??V> e = table[i]; e != null; e = e.next) { 
    Object k; 
    if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { 
    V oldValue = e.value; 
    e.value = value; 
    e.recordAccess(this); 
    return oldValue; 
    } 
    } 
    modCount++; 
    addEntry(hash?? key?? value?? i); 
    return null; 
    }

???????????????

????????key????null?????key??null???????table[0]??λ??????null??hashcode????0???????????key??hashCode()?????????????key??hash??????hash???????????洢Entry??????????е?λ?á?JDK??????????????Щ?????д????????hashCode()????????????Щ??????????С??hash????????????????????????????????hash??????????????hashCode()???????????????????????С??

??????indexFor(hash??table??length)???????????????????entry????洢????λ?á?

???????????????????????????????????????????й??????hashCode?????????????????????洢???????λ??[????bucket]???

????LinkedList??????????Entry???????next???????????????????????е?????????????????????????????

??????????????????entry????????????????洢???????????Entry??????????洢?????hashmap????λ???????????????entry?????????д????????????????????next?????????????????entry???????????洢??entry??????????????????????

????????????????key?????????value?????????????????????????滻?????????Entry?????洢λ?ú?hashmap??????????λ???entry???????????entry????equals??????????????е????ж????????????hashCode()??equals??????????????????equals??????????????滻??

??????????HashMap????key?????

get?????????????

????????????????HashMap?д洢???????????????????????????????HashMap?в???????

????????put????????????????key????佫??λ???value??????????з???null.