hashmap put方法问题。。。。

public V put(K key, V value) {
if (key == null)
return putForNullKey(value);
int hash = hash(key);
int i = indexFor(hash, table.length);
for (Entry e = table; 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;
}

void addEntry(int hash, K key, V value, int bucketIndex) {
if ((size >= threshold) && (null != table)) {
resize(2 * table.length);
hash = (null != key) ? hash(key) : 0;
bucketIndex = indexFor(hash, table.length);
}

createEntry(hash, key, value, bucketIndex);

}

void createEntry(int hash, K key, V value, int bucketIndex) {
Entry e = table;
table = new Entry<>(hash, key, value, e);
size++;
}

如果put 键索引相同key不同的元素,addEntry()怎么保存元素到链表尾部,createEntry()方法?

查看全部
a12136
a12136
2017/06/14 05:18
  • 链表
  • hashmap
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复