nerdexam
Oracle

1Z0-805 · Question #28

Given: ConcurrentMap<String, String> partList = new ConcurrentHashMap<> (); Which fragment puts a key/value pair in partList without the possibility of overwriting an existing Oracle 1Z0-805 Exam key?

The correct answer is E. if (!partlist.containsKey(key)) partList.put(key,"Blue Shirt"). 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.

Concurrency

Question

Given:

ConcurrentMap<String, String> partList = new ConcurrentHashMap<> (); Which fragment puts a key/value pair in partList without the possibility of overwriting an existing Oracle 1Z0-805 Exam key?

Options

  • ApartList.put (key,"Blue Shirt");
  • BpartList.putAbsent(key,"Blu Shirt")
  • CpartList.putIfNotLocked (key,"Blue Shirt");
  • DpartList.putAtomic (key,"Blue Shirt");
  • Eif (!partlist.containsKey(key)) partList.put(key,"Blue Shirt");

How the community answered

(37 responses)
  • A
    5% (2)
  • B
    8% (3)
  • D
    3% (1)
  • E
    84% (31)

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.

Topics

#ConcurrentHashMap#putIfAbsent#atomic operations#thread safety

Community Discussion

No community discussion yet for this question.

Full 1Z0-805 Practice