Oracle
1Z0-804 · Question #86
Given: ConcurrentMap <String, String> PartList = new ConcurrentMap<>(); Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing key?
The correct answer is B. partList.putIfAbsent(key,"Blue Shirt"). putIfAbsent(K key, V value) If the specified key is not already associated with a value, associate it with the given value.
Concurrency
Question
Given:
ConcurrentMap <String, String> PartList = new ConcurrentMap<>(); Which fragment puts a key/value pair in partList without the responsibility of overwriting an existing key?
Options
- ApartList.out(key,"Blue Shirt");
- BpartList.putIfAbsent(key,"Blue Shirt");
- CpartList.putIfNotLocked (key,"Blue Shirt");
- DpartList.putAtomic(key,"Blue Shirt")
- Eif (!partList.containsKey(key)) partList.put (key,"Blue Shirt");
How the community answered
(30 responses)- A3% (1)
- B70% (21)
- C7% (2)
- D3% (1)
- E17% (5)
Explanation
putIfAbsent(K key, V value) If the specified key is not already associated with a value, associate it with the given value.
Topics
#ConcurrentMap#putIfAbsent#atomic operations#thread-safe collections
Community Discussion
No community discussion yet for this question.