Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Collision in Java HashMap

807580Mar 5 2010 — edited Mar 8 2010
I 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"));

}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2010
Added on Mar 5 2010
11 comments
1,256 views