/**
The hash table data.
*/
//存放键值对的数组
private transient Entry<?,?>[] table;
/**
The total number of entries in the hash table.
*/
//大小
private transient int count;
/**
@serial
*/
//阀值
private int threshold;
/**
@serial
*/
//负载因子
private float loadFactor;
//默认初始容量为11,负载因子0.75
public Hashtable() {
this(11, 0.75f);
}
//1.8版本没有修改,没有维护红黑树结构
public synchronized V put(K key, V value) {
// Make sure the value is not null
if (value == null) {
throw new NullPointerException();
}
// Makes sure the key is not already in the hashtable.
Entry<?,?> tab[] = table;
int hash = key.hashCode();
//求余获得索引
int index = (hash & 0x7FFFFFFF) % tab.length;
@SuppressWarnings("unchecked")
Entry<K,V> entry = (Entry<K,V>)tab[index];
for(; entry != null ; entry = entry.next) {
if ((entry.hash == hash) && entry.key.equals(key)) {
V old = entry.value;
entry.value = value;
return old;
}
}
addEntry(hash, key, value, index);
return null;
}
/**
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。