Given:
ConcurrentMap<String, String> partList = new ConcurrentHashMap<> ();
Which fragment puts a key/value pair in partList without the possibility of overwriting an existing key?
A.
partList.put (key,”Blue Shirt”);
B.
partList.putAbsent(key,”Blu Shirt”)
C.
partList.putIfNotLocked (key,”Blue Shirt”);
D.
partList.putAtomic (key,”Blue Shirt”);
E.
if (!partlist.containsKey(key)) partList.put(key,”Blue Shirt”);
Explanation:
The containsKey method returns true if this map maps one or more keys to the
specified value.
So this statement adds a new key if they key is not present.
Reference: Class ConcurrentHashMap<K,V>
B if
putIfAbsent(key, “Blue Shirt”)