This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Dang, I wasn't clear. Sorry for the confusion. I want to take a string such as "Hello World", and display it's hashCode. That part is easy enough. Now I want to convert that hashCode back into the String "Hello World". Is that possible?
There is no way to tell from a hash code what type an object is or what its value(s) is/are. Well, there is a way to reconstruct a String value from its hashcode, but it's very ugly and not reliable. The only purpose of doing it may be as an exercise to see how the hashCode() works in a particular JDK implementation, or to have it formulated as a pure and theoretical math problem. So, while the reconstruction code below works, don't use it, -- for all intents and purposes, the street from an object to its hash code is a one way street, just like Joe indicated.
Output: original string is cat reconstructed string is cat
[ October 06, 2003: Message edited by: Eugene Kononov ]