title: Why does Java's hashCode() in String use 31 as a multiplier?
body: <p>Per the Java documentation, the <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html#hashCode()" rel="noreferrer">hash code</a> for a <code>String</code> object is computed as:</p>
  
  <blockquote>
  <pre><code>s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
  </code></pre>
    
    <p>using <code>int</code> arithmetic, where <code>s[i]</code> is the
     <i>i</i>th character of the string, <code>n</code> is the length of
     the string, and <code>^</code> indicates exponentiation.</p>
  </blockquote>
  
  <p>Why is 31 used as a multiplier?</p>
  
  <p>I understand that the multiplier should be a relatively large prime number. So why not 29, or 37, or even 97?</p>