1Z0-829 Working with Streams and Lambda Expressions Practice Question
A developer wants to find the longest word in a list of strings. Which stream operation should be used?
⚠ Common exam trap
Many candidates confuse `min()` and `max()` or incorrectly assume that sorting and taking the first element is the intended approach, overlooking the direct and efficient `max()` operation.
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().max(Comparator.comparingInt(String::length))
The `max()` terminal operation, when combined with a `Comparator` that compares strings by their length, returns the longest word in the stream. The `max()` operation uses the provided comparator to determine the 'largest' element according to the ordering, which in this case is the string with the greatest length.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
stream().sorted(Comparator.comparingInt(String::length).reversed()).findFirst()
Why it's wrong here
Works but not as direct as max.
- ✗
stream().min(Comparator.comparingInt(String::length))
Why it's wrong here
Returns shortest.
- ✗
stream().sorted(Comparator.comparingInt(String::length)).findFirst()
Why it's wrong here
Returns shortest.
- ✓
stream().max(Comparator.comparingInt(String::length))
Why this is correct
Correct.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.