Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing key?

Given:
ConcurrentMap <String, String> PartList = new ConcurrentMap<>();
Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing
key?

Given:
ConcurrentMap <String, String> PartList = new ConcurrentMap<>();
Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing
key?

A.
partList.out(key,”Blue Shirt”);

B.
partList.putIfAbsent(key,”Blue Shirt”);

C.
partList.putIfNotLocked (key,”Blue Shirt”);

D.
partList.putAtomic(key,”Blue Shirt”)

E.
if (!partList.containsKey(key)) partList.put (key,”Blue Shirt”);

Explanation:

putIfAbsent(K key, V value)
If the specified key is not already associated with a value, associate it with the given value.
40
Reference:java.util.concurrent,Interface ConcurrentMap<K,V>



Leave a Reply 3

Your email address will not be published. Required fields are marked *


BKhateib

BKhateib

The question is not totally true unless they use ”
ConcurrentMap concurrentMap = new ConcurrentHashMap();
as ConcurrentMap is an interface other than that the question is true