By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Java hashing

P: 1
Hi,

I've written a method to hash a String into a long, like so:

Expand|Select|Wrap|Line Numbers
  1. private static long stringToHash(String str){
  2.         long h = 0;
  3.  
  4.         for (int i = 0; i < str.length(); ++i)
  5.             h = 31 * h + str.charAt(i);
  6.  
  7.         return h;
  8. }
  9.  
This works great. However, I am having difficulty working out how to go from the long back to the original String.

Can anyone help?

Regards.
Nov 26 '06 #1
Share this Question
Share on Google+
1 Reply


Ganon11
Expert 2.5K+
P: 3,652
I'm not sure that hash code goes both ways - that is, I don't think an object can be reconstructed from its hash code.
Nov 26 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.