Courseiva
Working with Streams and Lambda ExpressionshardMultiple ChoiceObjective-mapped

1Z0-829 Working with Streams and Lambda Expressions Practice Question

Given:

List<String> words = Arrays.asList("apple", "banana", "cherry"); Map<Integer, List<String>> map = words.stream().collect(Collectors.groupingBy(String::length)); System.out.println(map);

What is the output?

⚠ Common exam trap

Candidates often confuse `groupingBy` with `toMap` or assuming the map keys are the string values themselves, leading candidates to reverse the key-value roles or misrepresent the grouped lists.

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

{5=[apple], 6=[banana, cherry]}

The `groupingBy` collector groups stream elements by a classifier function, here `String::length`. Each distinct length becomes a key in the map, and the values are lists of strings with that length. "apple" (length 5) maps to key 5, "banana" and "cherry" (both length 6) map to key 6, producing `{5=[apple], 6=[banana, cherry]}`.

Answer analysis

Option-by-option breakdown

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

  • [apple, banana, cherry]

    Why it's wrong here

    That would be a list, not a map.

  • {5=[5], 6=[6, 6]}

    Why it's wrong here

    Values are words, not lengths.

  • {5=[apple], 6=[banana, cherry]}

    Why this is correct

    Correct grouping.

  • {apple=[5], banana=[6], cherry=[6]}

    Why it's wrong here

    Map keys are lengths, not words.

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.