1Z0-829 Working with Streams and Lambda Expressions Practice Question
A developer needs to concatenate two Stream<String> into one. Which approach is most idiomatic?
⚠ Common exam trap
Many exam-takers confuse `flatMap` with concatenation or assume a non-existent `merge` method exists, because they recall similar operations from other APIs like `Map.merge()` or reactive streams, but the Java Stream API specifically provides `concat()` for this purpose.
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
✓
Stream.concat(stream1, stream2)
`Stream.concat(stream1, stream2)` is the idiomatic, built-in static method in the Java Stream API for concatenating two streams into a single sequential stream. It creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream, preserving encounter order.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
stream1.flatMap(s -> stream2)
Why it's wrong here
This would flatten each element of stream1 into the entire stream2, not concatenation.
- ✗
new StreamBuilder().add(stream1).add(stream2).build()
Why it's wrong here
Does not exist in standard API.
- ✓
Stream.concat(stream1, stream2)
Why this is correct
Correct: Static method that returns a concatenated stream.
- ✗
stream1.merge(stream2)
Why it's wrong here
No such method.
Go deeper
Related to this question
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 →
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.