nerdexam
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)
  • A
    3% (1)
  • B
    70% (21)
  • C
    7% (2)
  • D
    3% (1)
  • E
    17% (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.

Full 1Z0-804 Practice