Good implementation for the hashCode() for String objects
Usha Pnatha
Greenhorn
Joined: Aug 01, 2008
Posts: 27
posted
0
Hello Ranchers,
I'm required to implement a hashCode() for String objects. Each String will contain maximum 20 characters.
I went through the implementation in java.lang.String class. It's basically as follows:
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
Since there's no perfect hashing method, I believe that there can be alternatives to this way of implementation.
So, if anyone of you found a different implementation of the hashCode() for String objects(which would be more efficient than the provided one), please post you ideas here.