A

Admin • 832.27K Points
Coach

Q. Which method can replace an existing value in a Map only if it is currently mapped to a given value?

  • (A) putIfPresent()
  • (B) replace()
  • (C) override()
  • (D) update()
  • Correct Answer - Option(B)
  • Views: 18
  • Filed under category Java
  • Hashtags: Java Map

Explanation by: Admin

The `replace(K key, V oldValue, V newValue)` method replaces the value only if it's currently mapped to the given oldValue.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.