Per the Java documentation, the hash code for a String object is computed as:
String
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] <
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
This is because 31 has a nice property – it's multiplication can be replaced by a bitwise shift which is faster than the standard multiplication:
31 * i == (i << 5) - i