我需要以某种方式从 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.
很明显,你无法从相同的哈希码恢复不同的对象,所以这是根本不可能的,简单的逻辑。
关于java - 如何从 String.hashCode() 值获取字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60247494/