Question 272 of 513
1Z0-829 Working with Arrays and Collections Practice Question
Given: Map<String, Integer> map = new HashMap<>(); map.put("x", 10); map.put("y", 20); map.computeIfAbsent("x", k -> 30); map.computeIfPresent("z", (k,v) -> 40); System.out.println(map); What is the output?
⚠ Common exam trap
A common mix-up: candidates confuse `computeIfAbsent` with `put` or `merge`, assuming it always updates the value, and similarly assume `computeIfPresent` will insert a new key-value pair, when in fact both methods only act conditionally based on key presence.
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
✓
{x=10, y=20}
`computeIfAbsent` only inserts a mapping if the key is absent, and since "x" already exists with value 10, the lambda is not executed and the value remains 10. `computeIfPresent` only modifies a mapping if the key is present, and since "z" is not in the map, the lambda is not executed and no entry is added. Thus the map remains {x=10, y=20}.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Compilation fails
Why it's wrong here
The code compiles successfully.
- ✗
{x=30, y=20}
Why it's wrong here
Incorrect: computeIfAbsent does not replace existing values.
- ✗
{x=30, y=20, z=40}
Why it's wrong here
Incorrect: neither key is modified.
- ✗
{x=10, y=20, z=40}
Why it's wrong here
Incorrect: computeIfPresent does not add absent keys.
- ✓
{x=10, y=20}
Why this is correct
Correct: both conditions are false, so map unchanged.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 25, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.