HashMap集合特点

 

》HashMap集合特点

HashMap:是基于哈希表的Map接口实现。

哈希表的作用是用来保证键的唯一性的。

         不明白,直接看HashMap的put方法源码

//HashMap的put方法源码
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;
    }
原文地址:https://www.cnblogs.com/qq-757617012/p/4289626.html