String's hascode value can be changed? : <p>I need one help to understand String class, I wrote a program where i have created one string with new keyword and other one with literal, below is program. here my confusion is why string s (literal one) got changed , as string is immutable so only value have to change why hashcode got changed. is it because of intern() method,  Please help me to understand this.</p>

<pre><code>    String s = "xyz";
 String s1 = new String("abc"); 
System.out.println(s.hashCode()+"--&gt; hashcode before literal string"); 

System.out.println(s1.hashCode()+"--&gt; hashcode before new keyword string"); 

System.out.println(s+"--&gt; before case S value "); 
s = s1; 
System.out.println(s+ "--&gt; after case S value"); 

System.out.println(s.hashCode()+"--&gt; hashcode after literal string"); 

System.out.println(s1.hashCode()+"--&gt; hashcode after new keyword string");
</code></pre>

<hr>

<p>the output of this is </p>

<p>119193--> hashcode, before literal string</p>

<p>96354--> hashcode, before new keyword string</p>

<p>xyz--> before case S value </p>

<p>abc--> after case S value</p>

<p>96354--> hashcode, after literal string</p>

<p>96354--> hashcode, after  new keyword  string       </p>
