title: difference between equals() and hashCode()
body: <p>I want a brief definition about the equals() , &quot;==&quot; and hashCode(). If i run following code means the output will be &quot;true false 2420395 2420395&quot;. But i had understand that equals() method compares the string and &quot;==&quot; compares the reference. But in output the hashCcode() method prints the reference number for both strings as same then why the &quot;==&quot; returns &quot;false&quot;.</p>
  <pre><code>    String str = &quot;Name&quot;;
      String str1 = new String(&quot;Name&quot;);
      
      if (str.equals(str1))
          System.out.println(&quot;true&quot;);
      else
          System.out.println(&quot;false&quot;);
  
      if (str == str1)
          System.out.println(&quot;true&quot;);
      else
          System.out.println(&quot;false&quot;);
      
      System.out.println(str.hashCode());
      System.out.println(str1.hashCode());
  </code></pre>