Java 字符串情况下的哈希代码范围
我的代码中有字符串,出于某种目的,我取了它们的hashcode,但我想知道这些hashcode是否有任何范围,因为出现这种情况时,字符串的数量可能会超过hashcode的范围。那么hashcode的范围是什么呢?java中Java 字符串情况下的哈希代码范围,java,netbeans,hashcode,Java,Netbeans,Hashcode,我的代码中有字符串,出于某种目的,我取了它们的hashcode,但我想知道这些hashcode是否有任何范围,因为出现这种情况时,字符串的数量可能会超过hashcode的范围。那么hashcode的范围是什么呢?java中String类的hashcode方法是定义如下 public int hashCode() { int h = hash; if (h == 0) { int off = offset; char val[] = value;
String
类的hashcode
方法是定义如下
public int hashCode() {
int h = hash;
if (h == 0) {
int off = offset;
char val[] = value;
int len = count;
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}
public int hashCode(){
int h=散列;
如果(h==0){
int off=偏移量;
char val[]=值;
int len=计数;
对于(int i=0;i
它总是对你的字符串有一些价值……所以,我不知道;我不认为你会用完hashCode的...hashCode的范围是
int
的范围。对于任何所需的hashCode()
,都有一个String
,其中hashCode
hashCode的范围是Integer.MIN\u值到Integer.MAX\u值。是的,大多数字符串和代码都是重复的。鸽子洞原理。