Courseiva
Working with Arrays and CollectionsmediumMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

What does the Map.merge() method do if the specified key is absent?

⚠ Common exam trap

Oracle often tests the misconception that the remapping function is always called, leading candidates to incorrectly choose option A, when in fact the function is only invoked for existing keys.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Associates the key with the given value

When the specified key is absent in the map, the `Map.merge()` method associates the key with the given value without invoking the remapping function. This is specified in the Java API documentation: if the key is not present (or maps to null), the key is associated with the given non-null value.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Calls the remapping function with null and the value

    Why it's wrong here

    Remapping is called when key is present.

  • Associates the key with the given value

    Why this is correct

    If absent, put value.

  • Throws NullPointerException

    Why it's wrong here

    Only if value or remapping is null.

  • Removes the key if present

    Why it's wrong here

    That's not merge.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.