java - 如何从 String.hashCode() 值获取字符串?

标签 java string hash hashcode

我需要以某种方式从 java 中的哈希值中获取文本。 我有这个代码:

String myString = new String("creashaks organzine");
int hashCode = myString.hashCode();
System.out.println("Hash:" + hashCode); 

此代码的结果将为 0。 但“pollinating sandboxes”字符串的哈希值也将为 0。

可能存在冲突,例如与“creashaks Organzine”和“授粉沙箱”的冲突,我想找到像本例这样的冲突。

最佳答案

由于我没有足够的声誉来添加评论,我将引用另一个问题的解决方案

You know that several objects can have same hash(), as it mentioned in java doc for Object.hashCode()

It is not required that if two objects are unequal * according to the {@link java.lang.Object#equals(java.lang.Object)} * method, then calling the {@code hashCode} method on each of the * two objects must produce distinct integer results.

很明显,你无法从相同的哈希码恢复不同的对象,所以这是根本不可能的,简单的逻辑。

how can I get the String from hashCode

关于java - 如何从 String.hashCode() 值获取字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60247494/

相关文章:

java - 这些进口产品存在什么问题?

java - 带有线条和区域的程序地形纹理

c - 简单的 C 程序产生空白输出 - 没有错误

javascript - 使用javascript获取两个字符串之间的字符串

c# - 如何在 C# 中计算 OneDrive XOrHash

unix - AIX 操作系统中的 MD5 哈希值

使用 Maven 在 Eclipse 中运行 Pig 时出现 java.lang.VerifyError

java - 增强而不是覆盖 Maven 配置

c - C中的字符串和指针

algorithm - 散列机制将输入(0 到 2^32 - 1)散列为固定的可能 12 个字符的散列