The general contract of hashCode is as Javadoc says :
Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
Is the same word going to get the same hash every time that I run it?
During the execution of the application, invoking hashCode()
on equal words (I assume the word is a String
instance and equals()
has been overridden in String
) should return the same integer.
EDIT Since the javadoc for String.hashCode()
specifies how a String's hash code is computed, it is deterministic.
Returns a hash code for this string. The hash code for a String object is
computed as :
s[0]*31^(n-1) + s1*31^(n-2) + ... + s[n-1]