Why don't you use the default long option String.hashCode() (where some really smart guys are definitely working hard to make it effective - not to mention the thousands of eyes of developers who have already looked at this code)?
// adapted from String.hashCode() public static long hash(String string) { long h = 1125899906842597L; // prime int len = string.length(); for (int i = 0; i < len; i++) { h = 31*h + string.charAt(i); } return h; }
If you are looking for even more bits, perhaps you can use BigInteger Change:
As I mentioned in a comment on @brianegge's answer, there are not many abbreviations for hashes with more than 32 bits and most likely not one for hashes with more than 64 bits:
I could imagine a huge hash table distributed on dozens of servers, possibly storing tens of billions of mappings. For such a scenario, @brianegge still has a valid point here: 32 bits allow the use of 2 x 32 (about 4.3 billion) different hash keys. Assuming a strong algorithm, you should still have quite a few collisions. With 64-bit (18,446,744,073,000 different keys) you will definitely save, no matter what crazy scenario you need. The idea of using 128-bit keys (340,282,366,920,938,463,463,374,607,431 billion possible keys) is largely impossible.
To combine the hash for multiple fields, just make XOR multiply one by simple and add them:
long hash = MyHash.hash(string1) * 31 + MyHash.hash(string2);
A small simple place is there to avoid equal hash code for dial-up values, i.e. {'foo', 'bar'} and {'bar', 'foo'} are not equal and must have a different hash code. XOR is bad because it returns 0 if both values are equal. Therefore, {'foo', 'foo'} and {'bar', 'bar'} will have the same hash code.