title: String Vs Stringbuffer as HashMap key
body: <p>I am trying to understand why String and Stringbuilder/StringBuffer are treated differently when used as Hashmap keys. Let me make my confusion clearer with the following illustrations:</p>
  
  <p>Example #1, using String:</p>
  
  <pre><code>String s1 = new String("abc");
  String s2 = new String("abc");
  HashMap hm = new HashMap();
  hm.put(s1, 1);
  hm.put(s2, 2);
  System.out.println(hm.size());
  </code></pre>
  
  <p>Above code snippet prints '1'.</p>
  
  <p>Example #2, using StringBuilder(or StringBuffer):</p>
  
  <pre><code>StringBuilder sb1 = new StringBuilder("abc");
  StringBuilder sb2 = new StringBuilder("abc");
  HashMap hm = new HashMap();
  hm.put(sb1, 1);
  hm.put(sb2, 2);
  System.out.println(hm.size());
  </code></pre>
  
  <p>The above code snippet prints '2'.</p>
  
  <p>Could anyone please explain why the difference in behaviour.</p>