How can I have a HashMap with unique keys in java?

Hash map key is unique. Add duplicate key, then it will be overwritten.

 HashMap hm = new HashMap();
 hm.put("1", new Integer(1));
 hm.put("2", new Integer(2));
 hm.put("3", new Integer(3));
 hm.put("4", new Integer(4));
 hm.put("1", new Integer(5));// value integer 1 is overwritten by 5

By default Hashmap is not synchronized.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)