Courseiva
Working with Arrays and CollectionseasyMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

Exhibit

Refer to the exhibit.
```java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("X", 10);
        map.put("Y", 20);
        map.put("Z", 30);
        System.out.println(map.get("Y"));
    }
}
```

What is the output?

⚠ Common exam trap

The trap is that candidates may expect the output to include the key (e.g., "Y=20") because they confuse the return value of get() with an entry's toString() representation. The get() method returns only the value (or null if absent), not a formatted key-value string.

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

20

The code creates a HashMap and adds a mapping from key "Y" to value 20. When it retrieves the value for key "Y" using get(), it returns 20. The output is simply the integer 20, not the string "Y=20". Therefore, option C is correct.

Answer analysis

Option-by-option breakdown

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

  • Y=20

    Why it's wrong here

    The map's toString would show that, but not get method.

  • null

    Why it's wrong here

    Key "Y" exists, so value is returned, not null.

  • 20

    Why this is correct

    The key "Y" maps to 20.

  • Exception

    Why it's wrong here

    No exception; get returns the value or null if key absent.

About these practice questions

Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.