title: new String() vs literal string performance
body: <p>This question has been asked many times on StackOverflow but none of them were based on <strong>performance</strong>.</p>
  
  <p>In <em>Effective Java</em> book it's given that</p>
  
  <blockquote>
    <p>If  <code>String s = new String("stringette");</code> occurs in a loop or in a
    frequently invoked method, millions of String instances can be created
    needlessly. </p>
    
    <p>The improved version is simply the following: 
    <code>String s = "stringette";</code> This version uses a single String instance, rather than
    creating a new one each time it is executed.</p>
  </blockquote>
  
  <p>So, I tried both and found significant <strong>improvement</strong> in performance:</p>
  
  <pre><code>for (int j = 0; j &lt; 1000; j++) {
      String s = new String("hello World");
  }
  </code></pre>
  
  <p>takes about <strong>399 372</strong> nanoseconds.</p>
  
  <pre><code>for (int j = 0; j &lt; 1000; j++) {
      String s = "hello World";
  }
  </code></pre>
  
  <p>takes about <strong>23 000</strong> nanoseconds.</p>
  
  <p>Why is there so much performance improvement? Is there any <em>compiler optimization</em> happening inside?</p>