首页 > 其他 > 详细

HashMap集合特点

时间:2015-02-13 09:15:02      阅读:480      评论:0      收藏:0      [点我收藏+]

 

》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;
    }

HashMap集合特点

原文:http://www.cnblogs.com/qq-757617012/p/4289626.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!