Collision in Java HashMap
807580Mar 5 2010 — edited Mar 8 2010I am under the expression that if two key-value pairs hash to the same position, both values will be stored at the same hashcode position and no value will be overwritten. However, why is the following code giving me different result? Can anyone explain please
Thank you
Xin
import java.util.HashMap;
import java.util.Hashtable;
/**
*
* @author xint
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Test collision in HashMap
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("xint", "University of Toronto");
hm.put("xint", "University of California");
System.out.println(hm.containsValue("University of Toronto"));
}
}