Saturday, 27 August 2016

Behaviour of ConcurrentHashMap when it has Duplicate key.

Behaviour of ConcurrentHashMap when it has Duplicate key.

ConcurrentHashMap will overwrite previous value for a given key in Map. The object whos reference is lost are eligible for garage collection.

public class VoiceConcurrentHashMap {

public static void main(String[] args) {

ConcurrentHashMap<String,String> map = new ConcurrentHashMap<String, String>();
System.out.println(map);
map.put("Lnkedin", "profile");
map.put("Lnkedin", "profile");
map.put("Lnkedin", "jagdeesh");

}
}

ref :
1. Java API
2. Stackoverflow


No comments:

Post a Comment