A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a license for
this week in the
Java in General
Good implementation for the hashCode() for String objects
Joined: Aug 01, 2008
May 02, 2009 09:09:19
I'm required to implement a hashCode() for
objects. Each String will contain maximum 20 characters.
I went through the implementation in
class. It's basically as follows:
s*31^(n-1) + s*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.
Thanks in advance,
Joined: Sep 29, 2008
May 02, 2009 10:09:58
It might be quicker to search the web for different hash code implementations--there are a lot.
I agree. Here's the link:
subject: Good implementation for the hashCode() for String objects
variables in hashCode( ) and equals( )
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013