This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashCode" Watch "HashCode" New topic
Author

HashCode

Madi Muthukumaran
Greenhorn

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
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

How about using java.util.zip.CRC32 to generate a checksum for the string?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
norman richards
Author
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: http://aspose.com/file-tools
 
subject: HashCode
 
Similar Threads
Converting an integer to fixed length string
Correctly override equals and hashcode
generate unique fixed length code from a string
Creating a Unique ID from a String.
create a key from a string.