title: String s = new String("xyz"). How many objects has been made after this line of code execute?
body: <p>The commonly agreed answer to this interview question is that two objects are created by the code. But I don't think so; I wrote some code to confirm.</p>
  
  <pre><code>public class StringTest {
      public static void main(String[] args) {
          String s1 = "a";
          String s2 = "a";
          String s3 = new String("a");
          System.out.println("s1: "+s1.hashCode());
          System.out.println("s2: "+s2.hashCode());
          System.out.println("s3: "+s3.hashCode());
      }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <p><img src="https://i.stack.imgur.com/dxEOG.png" alt="Application output"></p>
  
  <p>Does this mean that only one object was created?</p>
  
  <p>Reaffirm: My question is how many object was created by the following code:</p>
  
  <pre><code>String s = new String("xyz")
  </code></pre>
  
  <p>Instead of the <code>StringTest</code> code.</p>
  
  <p>Inspired by @Don Branson, I debugged the below code:</p>
  
  <pre><code>public class test {
      public static void main(String[] args) {
          String s = new String("abc");
      }
  }
  </code></pre>
  
  <p>And the result is:</p>
  
  <p><img src="https://i.stack.imgur.com/7t0GY.png" alt="Enter image description here"></p>
  
  <p>The id of s is 84, and the id of "abc" is 82. What exactly does this mean?</p>