title: Example of ==, equals and hashcode in java
body: <p>Given this:    </p>
  
  <pre><code>String s1= new String("abc");
  String s2= new String("abc");
  String s3 ="abc";
  System.out.println(s1==s3);
  System.out.println(s1==s2);
  System.out.println(s1.equals(s2));
  System.out.println(s1.equals(s3));
  System.out.println(s1.hashCode());
  System.out.println(s2.hashCode());
  System.out.println(s3.hashCode());
  </code></pre>
  
  <p>Output is:</p>
  
  <pre class="lang-none prettyprint-override"><code>false
  false
  true
  true
  96354
  96354
  96354
  </code></pre>
  
  <p>Here <code>==</code> is giving false for each object but the hashcode for each String object is same. Why is it so? </p>