HashMap put方法分析
public V put(K key, V value) {
return putVal(hash(key), key, value, false, true);
}
hash():hash扰动函数
static final int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
如果key为空的话,直接返回0(存放位置的index也为0。因为Node.hash为0,通过路由寻址公式: