title: I am wondering, how we can verify two objects are created in String using new
body: <p>I have two Strings:</p>
  
  <pre><code>String s = "ABC";
  String s1 = new String("ABC");
  </code></pre>
  
  <p>In theory, If I am not wrong two objects are created in this case. I can verify that using hashcode().</p>
  
  <pre><code>public static void main(String[] args) {
          System.out.println(s.hashCode());
          System.out.println(s1.hashCode());
      }
  
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>2125849484
  2125849484
  </code></pre>
  
  <p>If I am not wrong, <code>hashcode()</code> only help us in verifying that both the strings having similar value assigned to it "ABC", because of that hashcode value is same. What about that 2nd object which is created in heap memory? How can we verify that whether it is created or not.</p>