I tested with java.util.IdentityHashMap, See
public class IdentityHashMapTest{
public static void main(String args[]) {
Map<String, String> m = new IdentityHashMap<String, String>();
m.put("John", "Doe");
m.put("John", "Paul");
System.out.println(m.size());
}
}
According to Java API said,
This class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values)
The result may be 2. But actual is 1. Is IdentityHashMap class wrong?
Change it to
and it will have two entries. String literals are pooled, so
"John" == "John".