Size of HashMap when using same literal/string Object as Key?
Please let me know if my understanding is correct:
Size of HashMap is 2 here because String equals(compare the state/content
and not the location on heap) method comes into picture when we put the
keys in the below map
Map hashMap = new HashMap();
hashMap.put("one", "1");
hashMap.put(new String("one"), "2");
hashMap.put("two", "3");
System.out.println("Hash Map KeySet Size : " + hashMap.keySet().size());
No comments:
Post a Comment