title: Are String hashCode in java pre-computed?
body: <p>in Java when I say.</p>
  
  <pre><code>String str= "abcd";
  str.hashCode(); 
  </code></pre>
  
  <p>My question is When is Hashcode calculated? @ line 1 or @ line 2? </p>
  
  <p>I am assuming , that hashcode is pre-computed. Whenever string is updated hashcode would also 'perhaps' update.</p>
  
  <p>or its the other way  i.e. every time you call <code>str.hashCode()</code> java computes its using the formula that's described <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#hashCode%28%29" rel="nofollow noreferrer">here</a>. </p>
  
  <p><a href="https://stackoverflow.com/questions/785091/consistency-of-hashcode-on-a-java-string">Consistency of hashCode() on a Java string</a></p>