Vex*_*toR 2 java collections hashmap
Hashcode具有类型int,因此它可以是负数和正数.但是HashMap使用hashcode来确定表中哪个索引放置键+值,比如,
hashcode / size_of_table = table_index.
但是如果HashMap确定在哪个索引中应该将key +值置于哈希码为负的情况下呢?
来自http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/HashMap.java:
static int indexFor(int h, int length) {
return h & (length-1);
}
Run Code Online (Sandbox Code Playgroud)