Overview
Domain 6 has two objectives. The first asks you to use object and primitive streams, with lambda expressions implementing functional interfaces, to create, filter, transform, process and sort data. The second covers decomposition, concatenation, reduction, grouping and partitioning on both sequential and parallel streams. Together they span the java.util.function interfaces, method references, Stream, IntStream, LongStream and DoubleStream, Optional and the Collectors class.
Questions are almost all code-reading. A pipeline runs and you choose the output, the type of the result, or the reason it fails to compile or throws. Laziness, the single-use nature of streams, and the exact map types produced by groupingBy and partitioningBy are frequent sources of wrong answers.
How it's tested
Expect pipelines of three to six operations, often over a List or Stream.of, followed by a question about the printed result or the declared type that would compile. Some items hide a problem: a reused stream, a lambda capturing a variable that changes, or a missing terminal operation that leaves peek silent.
-
Pipeline output
A stream filters, maps, sorts and collects, and you choose the exact printed result including map formatting.
-
Right functional interface
A lambda is assigned to a variable, and you pick the interface, such as Function, BiFunction, Supplier or UnaryOperator, that compiles.
-
Lazy or broken pipeline
Code has no terminal operation, reuses a stream, or captures a non-final local, and you identify what happens.
A pipeline calls peek to print each element, then filter and map, but never calls a terminal operation. Candidates often expect every element to print. Intermediate operations are lazy and only run when a terminal operation such as collect, count or forEach pulls elements through, so nothing prints. Adding findFirst would print only the elements needed to find the first match.
Objectives 2
Official objectives from the Oracle outline, in outline order.
6.1 Use Java object and primitive Streams, including lambda expressions implementing functional interfaces, to create, filter, transform, process, and sort data.Lambda syntax, method references, functional interfaces, stream sources, intermediate and terminal operations, Optional.
- What it means
- A lambda is a concise implementation of a functional interface's single abstract method, and a method reference is a shorthand for a lambda that calls an existing method. Streams process elements through a pipeline: a source, zero or more lazy intermediate operations such as filter, map and sorted, and one terminal operation that produces a result or side effect.
- What to understand
- Know the core java.util.function interfaces: Supplier, Consumer, BiConsumer, Function, BiFunction, UnaryOperator, BinaryOperator, Predicate and BiPredicate, plus primitive forms such as IntFunction, ToIntFunction and IntPredicate. Lambdas may use local variables only if they are effectively final. Method references come in four forms: static, bound instance, unbound instance and constructor. Streams come from collections, Stream.of, Arrays.stream, Stream.iterate and Stream.generate. Convert with mapToInt and mapToObj, and use boxed to return to objects. IntStream offers sum, average (OptionalDouble), max and range versus rangeClosed. Optional supports orElse, orElseGet, orElseThrow, map and ifPresent. A stream can be consumed only once; a second terminal call throws IllegalStateException.
- How it shows up
- Expect questions on lambda variable capture, matching a lambda to an interface, primitive stream return types and Optional methods.
- Common confusion
- Assuming IntStream.average returns a double, or that intermediate operations run without a terminal operation.
6.2 Perform decomposition, concatenation, and reduction, and grouping and partitioning on sequential and parallel streams.flatMap, Stream.concat, reduce, collect, groupingBy, partitioningBy and parallel behaviour.
- What it means
- This objective covers breaking elements apart and joining streams, for example with flatMap or mapMulti and Stream.concat, and reducing a stream to one result with reduce, collect or convenience methods such as count and max. It also covers grouping elements by a classifier and partitioning them by a predicate with Collectors, on sequential and parallel streams.
- What to understand
- reduce has three forms: with identity and accumulator, accumulator only (returning Optional), and identity, accumulator and combiner for parallel use. The identity must be neutral for the operation, or parallel results will be wrong. Collectors.groupingBy returns a Map whose values default to lists, and a downstream collector such as counting, mapping, summingInt or toSet changes the values. partitioningBy always produces a Map with both true and false keys, even when one group is empty. toMap throws IllegalStateException on duplicate keys unless given a merge function. Joining builds Strings with a delimiter, prefix and suffix. On parallel streams, forEach order is unpredictable while forEachOrdered keeps encounter order, findAny may return any element, and stateful lambdas cause unreliable results.
- How it shows up
- Expect grouping output with counting or mapping downstream, reduce identity mistakes, and parallel forEach ordering.
- Common confusion
- Expecting partitioningBy to omit an empty group, or treating Collectors.counting results as Integer rather than Long.
High-yield concepts
The terms, rules and formulas this domain turns into questions most often.
-
Lazy evaluation
Intermediate operations run only when a terminal operation pulls elements.
- Remember
- No terminal operation means no work.
- Tested as
- peek and print questions.
- Trap
- Expecting output from an unterminated pipeline.
-
Single use
A stream can be consumed once.
- Remember
- A second terminal call throws IllegalStateException.
- Tested as
- Runtime exception questions.
- Trap
- Reusing a stream variable.
-
Effectively final capture
Lambdas read locals that never change after assignment.
- Remember
- Modifying the local anywhere breaks compilation.
- Tested as
- Compile-error questions.
- Trap
- Thinking only changes inside the lambda matter.
-
Method reference forms
Static, bound, unbound and constructor references.
- Remember
- String::length is unbound, using the stream element.
- Tested as
- Lambda-to-reference conversions.
- Trap
- Confusing bound and unbound forms.
-
Primitive streams
IntStream, LongStream and DoubleStream.
- Remember
- average returns OptionalDouble; sum returns a primitive.
- Tested as
- Return type questions.
- Trap
- Assigning average to a double directly.
-
Optional
Container that may hold a value.
- Remember
- orElseGet is lazy; orElse always evaluates its argument.
- Tested as
- Optional chain questions.
- Trap
- Calling get on an empty Optional.
-
reduce identity
Starting value for a reduction.
- Remember
- Must be neutral, such as 0 for sum and 1 for product.
- Tested as
- Parallel reduction questions.
- Trap
- Using a non-neutral identity on a parallel stream.
-
groupingBy
Collector that groups elements by a classifier.
- Remember
- Default values are Lists in a HashMap.
- Tested as
- Map output questions.
- Trap
- Expecting sorted keys without TreeMap::new.
-
partitioningBy
Collector that splits elements by a predicate.
- Remember
- Always contains both true and false keys.
- Tested as
- Map output questions.
- Trap
- Expecting one key when all elements match.
-
toMap
Collector building a Map from key and value functions.
- Remember
- Duplicate keys throw without a merge function.
- Tested as
- Exception questions.
- Trap
- Assuming later values overwrite earlier ones.
-
flatMap
Maps each element to a stream and flattens the results.
- Remember
- Turns a stream of lists into a stream of elements.
- Tested as
- Decomposition questions.
- Trap
- Using map and getting a stream of streams.
-
forEachOrdered
Terminal operation keeping encounter order.
- Remember
- Use it when order matters on a parallel stream.
- Tested as
- Parallel output questions.
- Trap
- Expecting forEach to keep order in parallel.
Side by side
Concepts candidates mix up, compared on the point that decides the answer.
Common functional interfaces
| Concept | Meaning | Key difference | Common trap |
|---|---|---|---|
| Supplier<T> | No input, returns T | get() | Expecting it to accept an argument |
| Consumer<T> | Takes T, returns nothing | accept(T) | Using it where a result is needed |
| Function<T,R> | Takes T, returns R | apply(T) | Using it where both types must match, which is UnaryOperator |
| Predicate<T> | Takes T, returns boolean | test(T) | Returning Boolean objects from a Function instead |
| BinaryOperator<T> | Takes two T values, returns T | apply(T, T); used by reduce | Mixing it up with BiFunction of different types |
Grouping collectors
| Concept | Meaning | Key difference | Common trap |
|---|---|---|---|
| groupingBy(f) | Groups into Map<K, List<T>> | Keys from a classifier; any number of keys | Expecting a sorted map |
| groupingBy(f, counting()) | Counts per group | Values are Long | Declaring the map with Integer values |
| partitioningBy(p) | Splits by a predicate | Exactly two Boolean keys | Expecting an empty group to be omitted |
| toMap(k, v) | One value per key | Throws on duplicate keys without a merge function | Assuming last value wins |
Exam traps
Each trap is an answer that looks right. Learn the clue that should change your mind.
-
Missing terminal operation
- What candidates pick
- Chooses output listing every element printed by peek.
- Why it looks right
- The pipeline looks complete.
- Why it's wrong
- Without a terminal operation, intermediate operations never run, so peek prints nothing.
Clue to watch for A pipeline that ends with map or filter.
-
Partition omits empty side
- What candidates pick
- Picks a map with only the true key.
- Why it looks right
- Every element matched the predicate.
- Why it's wrong
- partitioningBy always creates both keys, mapping the empty side to an empty list or zero count.
Clue to watch for A partition where all elements satisfy the test.
-
toMap last wins
- What candidates pick
- Expects duplicates to overwrite silently.
- Why it looks right
- Map.put overwrites, so this feels consistent.
- Why it's wrong
- Collectors.toMap throws IllegalStateException on a duplicate key unless a merge function is supplied.
Clue to watch for Key function that maps two elements to the same key.
-
Captured local can change
- What candidates pick
- Accepts a lambda that reads a counter incremented later.
- Why it looks right
- The lambda itself does not modify the counter.
- Why it's wrong
- Any later assignment makes the local not effectively final, so the lambda fails to compile.
Clue to watch for A local variable reassigned after the lambda is declared.
-
Wrong reduce identity
- What candidates pick
- Uses an identity of 10 with a parallel sum and expects the usual result plus 10.
- Why it looks right
- Sequentially the identity is added once.
- Why it's wrong
- In parallel the identity is applied in each chunk, so a non-neutral identity gives unpredictable totals.
Clue to watch for A parallel stream with reduce and a non-zero identity for addition.
-
Counting returns Integer
- What candidates pick
- Declares Map<String, Integer> for groupingBy with counting.
- Why it looks right
- Counts feel like ints.
- Why it's wrong
- Collectors.counting produces Long values, so a Map<String, Integer> target does not compile.
Clue to watch for A declared map type next to Collectors.counting().
Answer framework
Read stream questions in this order so the hidden problems surface early.
- Confirm that the pipeline compiles: lambda parameter and return types match the functional interface, and captured locals are effectively final.
- Check that there is exactly one terminal operation and that no stream variable is consumed twice, since otherwise nothing runs or an exception occurs.
- Trace elements one at a time through intermediate operations, remembering laziness, short-circuiting operations such as findFirst and limit, and sorted's need to see all elements.
- Determine the result type precisely: Optional or primitive optional, Long from counting, Map with List values, or two-key Map from partitioningBy.
- If the stream is parallel, decide which parts remain deterministic, such as collect and properly identified reduce, and which do not, such as forEach and findAny.
Practice question
Want more like this? The 1Z0-830 practice test has questions for every domain.
Checklist
0 of 12
Tick each one you can do without notes. Your ticks stay in this browser.
Study strategy
Begin with functional interfaces, because every stream question depends on them. Write one lambda for each core interface, assign it to a typed variable, and then convert it to a method reference where possible. Try capturing a local variable and then reassigning it to read the compiler error.
Next, build pipelines in small steps. Start with filter and map over a list of records, add sorted with a Comparator, then add peek to watch laziness, and finally swap in limit or findFirst to see short-circuiting. Repeat with IntStream to learn the primitive return types such as OptionalDouble from average.
Spend a full session on collectors. Group the same data with groupingBy using counting, mapping, summingInt and a TreeMap supplier, then compare with partitioningBy and toMap, including a duplicate key. Finish with parallel streams: run reduce with a correct and an incorrect identity, and compare forEach with forEachOrdered. Keep a page of result types, since many questions turn on them.
FAQ
How much of 1Z0-830 is Domain 6, Working with Streams and Lambda expressions?
Oracle does not publish weights. This section has two dense objectives, and we plan for about seven of the 50 questions plus lambdas inside other sections.
What does decomposition mean in this objective?
Oracle does not define it. Study the operations that break elements or streams apart, such as flatMap and mapMulti, and how parallel streams split their source into chunks.
Do I need to know every Collectors method?
Focus on toList, toSet, toMap, joining, counting, summingInt, averagingInt, mapping, filtering, groupingBy, partitioningBy and teeing, along with their result types.
Is Stream.toList the same as Collectors.toList?
Both return a List, but Stream.toList, added in Java 16, returns an unmodifiable list, while Collectors.toList makes no guarantee about modifiability.
Can a lambda throw a checked exception?
Only if the functional interface's method declares it. The standard java.util.function interfaces declare none, so checked exceptions must be handled inside the lambda body.
Are parallel streams always faster?
No. Parallel streams add overhead and can give non-deterministic output for order-sensitive operations, so exam questions focus on correctness rather than speed.
Test your Domain 6 knowledge
You have reviewed functional interfaces, method references, stream pipelines, primitive streams, Optional, reduction and Collectors. Test whether you can predict pipeline output and result types.
Keep going
- Training Training Built on your Weak areas
- Practice test Questions by domain, with explanations
- Mock exam Full length, timed like the real exam
- Readiness test Find your weakest domain in minutes
- Cheat sheet Key terms and formulas on one page
- Ask the 1Z0-830 AI tutor Get any concept explained your way