Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashCode

 
Madi Muthukumaran
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using java.util.zip.CRC32 to generate a checksum for the string?
 
norman richards
Author
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic