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]
Neil Coffey explains why 31 is used under Ironing out the bias.
Basically using 31 gives you a more even set-bit probability distribution for the hash function.