title: Please explain intern() method functionality
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1855170/when-should-we-use-intern-method-of-string">When should we use intern method of String?</a><br>
    <a href="https://stackoverflow.com/questions/10578984/what-is-string-interning">what is string interning?</a>  </p>
  </blockquote>
  
  
  
  <p>Please explain the inner workings of the following code:</p>
  
  <pre><code>System.out.println(new String("ABC").intern()==new String("ABC").intern());
  </code></pre>
  
  <p>In the above code it prints "true". But according java rules, in the case of the new operator, it always creates a new object.  <code>object.intern()</code> method also creates an object in the string pool. So my question is, in the above code how many objects are created.</p>
  
  <p>According to me, 3 new objects will created.  One goes to String pool, and two anonymous objects will be created by the new operator. But i am not sure. </p>
  
  <p>If i am wrong please explain.</p>