It's not a secret anymore!
The moose likes Java in General and the fly likes HashCode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashCode" Watch "HashCode" New topic


Madi Muthukumaran

Joined: Oct 16, 2003
Posts: 11
I just have a long string and i want to make a integer of fixed length from that string, i thought of using hashcode() method to get the integer, but the hashcode will not be unique, can one tell me how can i convert the string to UNIQUE FIXED LENGTH INTEGER.
Thaning you
M. Muthu
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

How about using to generate a checksum for the string?

[How To Ask Questions On JavaRanch]
norman richards
Ranch Hand

Joined: Jul 21, 2003
Posts: 367
You can't guarantee uniqueness with a fixed length hash if your source is arbitrary length strengths. But, you can do a lot better than the Java hashcode. If you need maximal uniqueness, then look for hashing functions used in encryption. MD5 and SHA1 are popular examples. I think they are both well supported by the JCE. Look for the MessageDigest class.
I agree. Here's the link:
subject: HashCode
It's not a secret anymore!