Java:哈希函数输入字符串

Java:哈希函数输入字符串,java,string,hash,hashcode,Java,String,Hash,Hashcode,我正在寻求帮助创建一个哈希函数,该函数将从字符串中输入用户数据,并将其转换为整数值,同时跳过空格。我很困惑为什么它不工作,以及如何让它获得可能被输入的空白,并感谢帮助 代码: 您的代码在unchangedinStr上调用hashCode()。在调用hashCode之前,应清除inStr中的空白,以确保仅在空白处不同的字符串的哈希代码相同: String a = "a bc"; String b = "ab c"; String c = "a b c"; int hashA = a.<rem

我正在寻求帮助创建一个哈希函数,该函数将从字符串中输入用户数据,并将其转换为整数值,同时跳过空格。我很困惑为什么它不工作,以及如何让它获得可能被输入的空白,并感谢帮助

代码:


您的代码在unchanged
inStr
上调用
hashCode()
。在调用
hashCode
之前,应清除
inStr
中的空白,以确保仅在空白处不同的字符串的哈希代码相同:

String a = "a bc";
String b = "ab c";
String c = "a b c";
int hashA = a.<remove-white-space>.hashCode();
int hashB = b.<remove-white-space>.hashCode();
int hashC = c.<remove-white-space>.hashCode();
String a=“a bc”;
字符串b=“ab c”;
字符串c=“a b c”;
int hashA=a..hashCode();
int hashB=b..hashCode();
int hashC=c..hashCode();
是您需要编写的东西。请咨询有关此任务的帮助


如果您正确执行任务,
hashA
hashB
hashC
将彼此相等。

什么不起作用?什么不起作用?你期望的产出是什么?你得到了什么?您看到的确切错误消息是什么?我期望的是某种类型的整数输出,具体取决于字符串输入是什么。如果您期望的是整数,为什么
hashValue
类型为
string
?请删除此处不必要的赋值
string hashValue=inStr
只需执行
int hashValue=inStr.hashCode()
String a = "a bc";
String b = "ab c";
String c = "a b c";
int hashA = a.<remove-white-space>.hashCode();
int hashB = b.<remove-white-space>.hashCode();
int hashC = c.<remove-white-space>.hashCode();