Streams and Lambda Expressions Flashcards
7 cards from real OCP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Streams and Lambda Expressions flashcards as text
Which terminal operation returns an OptionalDouble representing the average of a DoubleStream?
Answer: average()
DoubleStream.average() is a terminal operation that returns OptionalDouble containing the arithmetic mean of all elements.
What does the flatMap() operation do that map() does not?
Answer: It flattens a stream of streams into a single stream
flatMap() maps each element to a stream and then flattens all those streams into a single stream, whereas map() returns one element per input element.
Which functional interface is used by Stream.filter()?
Answer: Predicate
Stream.filter() accepts a Predicate, which is a functional interface with a single abstract method test(T t) returning boolean.
What is the result of calling Stream.of(1, 2, 3).reduce(0, Integer::sum)?
Answer: 6
reduce(identity, accumulator) returns the result directly (not wrapped in Optional) because the identity element guarantees a value; 0+1+2+3=6.
Which of the following creates a lazy infinite stream of random doubles?
Answer: Stream.generate(Math::random)
Stream.generate(Supplier) produces an infinite sequential unordered stream where each element is generated by the provided Supplier.
What does Collectors.joining(", ") do when used with Stream.collect()?
Answer: Concatenates stream elements into a single String separated by ", "
Collectors.joining(delimiter) concatenates all CharSequence elements of a stream into a single String with the given delimiter between each element.
Which method on Optional executes an action only if a value is present?
Answer: ifPresent(Consumer)
Optional.ifPresent(Consumer) invokes the given consumer with the value if present, and does nothing if the Optional is empty.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. Exam facts are checked against the official sources listed below. Not reviewed by a subject-matter expert. Editorial policy
Sources & references
Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy
- oracle.com — Test dates, score release, retake policy · verified Oct 2026
- mylearn.oracle.com — Test delivery, exam format, passing score, time limit · verified Oct 2026