String abc = "abc";
String abc2 = new String("abc");
System.out.println(abc == abc2); //false
Map<String, Integer> map = new HashMap<String, Integer>();
map.put(abc, 2);
System.out.println("map.get(abc)" + map.get("abc")); //2
map.put(abc2, 1234);
System.out.println("map.get(abc)" + map.get("abc")); //1234
If abc
and abc2
are not equal then why Hashmap
is overriding values?