• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

HashCode to String

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the String method hashCode() to obtain the hash value of a specified String. I need to to convert the hash value back to the original String. Can anybody help? Essentialy this should be simple but I am stumped!
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anthony Alberts:
I am using the String method hashCode() to obtain the hash value of a specified String. I need to to convert the hash value back to the original String. Can anybody help? Essentialy this should be simple but I am stumped!


It's not only not simple, it's impossible!
First, there is no guarantee that two different Strings also differ in their hashcode. In fact there *have* to be Strings which are not equal but share the same hashcode - after all, there are much more possible values for a String than possible values for an int!
Second, there is no guarantee on how the hashcode of a String is calculated, afaik - the algorithm might very well differ strongly between JRE implementations.
 
Anthony Alberts
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that. I assume then that my understanding of Hash leaves much to be desired or possibly smo'kn too much of the above.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...then you may appreciate taking a look at Roedy Green's Java Glossary on hashCode.
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic