底层实现:数组+链表
/**
* The hash table data.
*/
private transient Entry<?,?>[] table;
/**
* The total number of entries in the hash table. 在Hash表中的总条目
*/
private transient int count;
/**
* The table is rehashed when its size exceeds this threshold. (The
* value of this field is (int)(capacity * loadFactor).)
* 暂时 当前大小 加载因子*容量
*
* @serial
*/
private int threshold;
/**
* Constructs a new, empty hashtable with a default initial capacity (11)初始总容量
* and load factor (0.75). 加载因子
*/
public Hashtable() {
this(11, 0.75f);
}
//当前容量阈值
threshold = (int)Math.min(initialCapacity * loadFactor, MAX_ARRAY_SIZE + 1);
put:
if (value == null) {
throw new NullPointerException();
}
key:不能为空!
数组哈希表索引值:int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length;