这是 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; }我想问的是,table[0]如果构成链,其链是一个对象吗?还是链的每个元素是一个对象,源代码好像是一个对象。问2:如果构成链,教材里面说e 链在 e.next 的后面,怎么源代码看是e 直接被替换了。
帮忙看看
帮忙看看
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货