Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

hashCode help



I am trying to implement a hashCode method to return the last few chars of a word or number inputted using my JUnit test. Here is my current method:

@Override
public int hashCode(String value){
String test = value;
int hash = 1;
int len = test.length();
System.out.println(len);
for ( int i=0; i<len; i++ )
      {
      hash = 31 * hash + len;
      }
   return hash;
}

On my test results I get a failure saying it expected a and got an int (98727). Can anyone help me write a hashCode method that returns that last two chars of a word or int? Any help would be most appreciated.