1Z0-829 · domain
Working with Streams and Lambda Expressions
Practise Oracle Certified Professional Java SE 17 Developer 1Z0-829 Working with Streams and Lambda Expressions practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.
Focused practice
Practice Working with Streams and Lambda Expressions questions
Scored sessions drawing only from this domain — pick a length below.
Start 20-question practice test →What this domain covers
What to know about Working with Streams and Lambda Expressions
Working with Streams and Lambda Expressions questions test whether you can apply the concept in context, not just recognise a definition.
How the topic appears in realistic exam-style scenarios.
Which detail in the question changes the correct answer.
How to eliminate plausible but wrong options.
How to connect the question back to the wider exam objective.
Watch out for
Common Working with Streams and Lambda Expressions exam traps
- ▸Answering from memory before reading the full scenario.
- ▸Missing a constraint such as cost, availability, security, scope or command context.
- ▸Choosing a broad answer when the question asks for the most specific fix.
- ▸Ignoring why the wrong options are tempting.
Question index
All Working with Streams and Lambda Expressions questions (89)
Click any question to see the full explanation, or start a practice session above.
What is the output?
Medium2A developer wants to create a stream that repeatedly generates random integers. Which method should be used?
Medium3A developer is designing a method that processes a stream of Employee objects. The method needs to group employees by department and then, within each department, sort by salary in descending order, and collect the top 3 highest-paid employees per department into a list. Which approach correctly accomplishes this using streams?
Medium4Given: 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?
Hard5A company runs a financial application that processes a stream of millions of transaction records daily. Each record is a 'Transaction' object with fields: id, amount, currency, timestamp. The system currently uses a parallel stream to group transactions by currency and compute the sum of amounts per currency, using the following code: Map<String, Double> result = transactions.parallelStream() .collect(Collectors.groupingBy(Transaction::getCurrency, Collectors.summingDouble(Transaction::getAmount))); Recently, performance has degraded significantly. Analysis shows that the stream source is a LinkedList, and the operation involves a large number of distinct currencies (over 1000). The JVM is running on a machine with 4 cores. Which is the best course of action to improve performance?
Hard6A stream pipeline uses sorted() with a Comparator that calls a thread-unsafe method on each element. The pipeline is parallel. What is the likely outcome?
Hard7Which TWO are correct about parallel streams in Java? (Choose TWO.)
Hard8Which statement about the Stream API is true?
Easy9Given: List<String> words = List.of("apple", "banana", "cherry"); var result = words.stream().filter(s -> s.length() > 5).collect(Collectors.toUnmodifiableList()); What happens if another thread tries to add to result?
Hard10Given a list of strings, which of the following will produce a Map<String, Long> counting the occurrences of each string?
Hard11What is the output?
Easy12A developer wants to find the longest word in a list of strings. Which stream operation should be used?
Medium13Match each exception class to its category (checked/unchecked).
Medium14Which of the following lambda expressions is syntactically invalid?
Hard15Which of the following is a terminal operation of the Stream API?
Easy16Which TWO statements about the Stream API are correct? (Choose two.) A. A stream can be traversed multiple times. B. The peek() method is an intermediate operation. C. The findFirst() method returns an Optional. D. The collect() method is an intermediate operation. E. The map() method returns a stream of the same type.
Hard17Which TWO statements about method references are true? (Choose two.)
Medium18A company needs to process a stream of orders and filter out orders that are not in the 'SHIPPED' status. Then they want to collect the order IDs into a list. Which of the following correctly uses lambda expressions to achieve this?
Medium19Which THREE of the following are valid ways to create a Stream<String>? (Choose three.)
Medium20Which functional interface is most appropriate for a lambda that takes a String and returns nothing?
Easy21A method receives a List<String> and needs to transform it to a Map where the key is the first three characters of each string and the value is the string itself. If two strings have the same prefix, the later one should override the earlier. Which collector achieves this?
Medium22A developer implements a reduction using reduce() to concatenate strings from a stream. The code: Optional<String> result = stream.reduce((s1, s2) -> s1.concat(s2)); The operation works but the developer is concerned about performance with large streams. Which change would most likely improve performance?
Hard23Which three are terminal operations of the Stream interface? (Choose three.)
Medium24A stream pipeline uses the peek method for debugging. Which statement about peek is correct?
Easy25Refer to the exhibit. What is the output?
Medium26A developer is converting legacy for loops to streams. The legacy code: List<Integer> list = new ArrayList<>(); for (String s : strings) { if (s.length() > 5) { list.add(s.length()); } } They write: List<Integer> list = strings.stream() .filter(s -> s.length() > 5) .map(s -> s.length()) .collect(Collectors.toList()); But it doesn't compile. The error is: 'cannot find symbol: method collect(Collector<Object,?,List<Object>>)'. What is the likely issue?
Easy27Refer to the exhibit. What is the output?
Medium28The code fails to compile. What is the reason?
Easy29Refer to the exhibit. What is the output?
Medium30Which code will successfully produce an Optional<Integer> that contains the maximum value from a list of integers?
Easy31A developer wants to collect elements from a stream into an immutable List. Which collector should be used?
Medium32What does the following code print? List<Integer> list = List.of(1, 2, 3, 4, 5); list.stream().filter(i -> i % 2 == 0).forEach(System.out::print);
Easy33Which TWO of the following are characteristics of a well-designed lambda expression? (Choose two.)
Easy34Assuming the code runs in a multithreaded environment, which statement best describes the behavior?
Hard35A company runs a Java 17 microservice that processes real-time financial transactions. The application receives a large number of transactions per second, each with a timestamp, amount, and type. The current implementation uses a sequential stream to filter and aggregate transactions into a Map<TransactionType, DoubleSummaryStatistics>. The team observes high latency and CPU spikes during peak loads. They suspect the stream pipeline is inefficient. The pipeline code is: Map<TransactionType, DoubleSummaryStatistics> stats = transactions.stream() .filter(t -> t.getTimestamp().isAfter(Instant.now().minusSeconds(60))) .collect(Collectors.groupingBy(Transaction::getType, Collectors.summarizingDouble(Transaction::getAmount))); The transactions list is an ArrayList that is frequently modified by other threads (adding new transactions). The system has multiple CPU cores available. Which of the following changes is the MOST effective way to improve performance while maintaining correctness?
Hard36A team implements a stream pipeline that processes a large dataset in parallel. They use a stateful lambda expression inside the map operation to maintain a count. What is the most likely outcome?
Medium37A team is developing a real-time data processing pipeline that reads sensor data from a message queue. The pipeline uses a flatMap operation that calls an external geocoding service for each sensor reading. The external service has a rate limit of 10 requests per second and is slow (150ms average response time). The current code: sensorStream.parallelStream() .flatMap(reading -> getGeocode(reading).stream()) .forEach(system.out::println); The application is overloaded because parallel stream fires many concurrent requests, exceeding the rate limit and causing failures. They need to process all sensor data but must respect the rate limit. Which approach should they use?
Hard38A lambda expression that takes two integers and returns a boolean indicating whether the first is greater than the second is best represented by which functional interface?
Easy39Refer to the exhibit. What is the output?
Medium40A developer uses a parallel stream to process a large collection and wants to collect results into a List while preserving encounter order. Which of the following collectors will guarantee order preservation?
Medium41Which TWO statements are true about the Stream API and lambda expressions in Java 17?
Hard42Which THREE of the following are valid ways to create an infinite stream? (Choose three.)
Hard43A developer is refactoring a legacy codebase to use streams. The original code iterates over a list of 'Order' objects, filters orders with status 'PENDING', sorts them by date, and collects the order IDs into a set. Which stream pipeline correctly replaces this logic?
Medium44Which TWO are valid lambda expressions? (Choose two.) A. (int a, int b) -> a + b B. a, b -> a + b C. (a, b) -> a + b D. (a, b) -> { a + b; } E. (int a, b) -> a + b
Medium45A developer needs to concatenate two Stream<String> into one. Which approach is most idiomatic?
Easy46A developer writes the following code using the Stream API: List<String> list = List.of("a", "b", "c"); String result = list.stream().reduce("", (s1, s2) -> s1 + s2); System.out.println(result); What is the output?
Easy47What is the output of the following code? ```java System.out.println(Stream.of(1, 2).map(i -> i * 2.0).count()); ```
Hard48What is the result of executing this code?
Medium49A team is implementing a parallel stream to process a large dataset. They notice that the operation is slower than expected. Which change is most likely to improve performance?
Hard50A developer writes a stream pipeline that uses flatMap and filter but notices that the intermediate streams created by flatMap are never garbage-collected early, causing memory pressure. What is the most effective optimization to reduce memory usage?
Hard51A lambda that takes a String and returns its length is assigned to which functional interface?
Easy52A developer writes: List<Integer> list = List.of(1, 2, 3); Optional<Integer> opt = list.stream().reduce((a, b) -> a + b); System.out.println(opt.get()); What is the result?
Medium53A company uses a large dataset of customer orders. They want to compute statistics: total orders, average amount, and maximum amount per city. They write: Map<String, IntSummaryStatistics> stats = orders.stream() .collect(Collectors.groupingBy(Order::getCity, Collectors.summarizingInt(Order::getAmount))); The code works but is slower than expected when run on a large dataset. They suspect the grouping operation is not taking advantage of parallelism. They want to improve performance by making the collector concurrent. Which change is correct?
Medium54A method returns an Optional<String>. The developer wants to transform the value inside the Optional to uppercase and print it, but only if present. Which best-practice approach uses streams?
Easy55Given a list of integers, a developer wants to compute the sum of squares of numbers greater than 10. The following code is written: int sum = list.stream().filter(i -> i>10).mapToInt(i->i*i).sum(); But the sum is incorrect. What is the most likely reason?
Hard56Which two statements are true about the peek method of the Stream API? (Choose two.)
Easy57Refer to the exhibit. What is the output?
Hard58A company processes financial transactions. Each transaction is represented by a Transaction object with fields: amount (double), currency (String), and type (String). The requirement is to compute the total amount of all transactions of type 'SALE' in USD. The transactions are stored in a List<Transaction>. Which code correctly accomplishes this using streams?
Medium59Which TWO statements about lambda expressions are true? (Choose two.) A. A lambda expression can be assigned to a functional interface variable. B. A lambda expression can access final or effectively final local variables. C. A lambda expression can throw any checked exception. D. A lambda expression can be used to create an instance of an abstract class. E. A lambda expression can be used to implement multiple abstract methods.
Hard60Refer to the exhibit. What is the output? ```java import java.util.stream.IntStream; public class Example { public static void main(String[] args) { int sum = IntStream.rangeClosed(0, 5) .filter(i -> i >= 0) .sum(); System.out.println(sum); } } ```
Medium61Which two statements about the Stream API are true? (Choose two.)
Easy62What is the output of the code above?
Medium63Which are valid method references in Java 17?
Hard64Refer to the exhibit. What is the output?
Hard65Which TWO are terminal operations on the Stream interface? (Choose two.)
Easy66A Java team is processing a large dataset with parallel streams. They notice inconsistent results due to non-atomic operations on shared mutable state. Which approach should they use to ensure thread-safety while maximizing performance?
Medium67A developer wants to count how many strings in a list have length greater than 5. Which is the correct implementation?
Easy68Refer to the exhibit. What is the output?
Hard69Which TWO are valid ways to obtain a Stream from a List<String> named 'list'? (Choose two.)
Medium70Refer to the exhibit. What is the output?
Hard71Refer to the exhibit. What is the output?
Hard72A developer is processing a stream of strings and needs to create a map where the key is the string length and the value is a list of strings of that length. They write the following code: Map<Integer, List<String>> map = strings.stream() .collect(Collectors.groupingBy(String::length)); The code works correctly in a sequential stream, but when they switch to parallelStream, they notice that sometimes the map contains fewer keys than expected. They suspect that the issue is related to the default map implementation used by groupingBy. What is the most likely cause and the correct fix?
Easy73A financial services company has a microservice that processes trade confirmations. The service receives a stream of Trade objects (with fields: id (long), symbol (String), quantity (int), price (double)) and needs to compute the total value (quantity * price) for each symbol, but only for trades with quantity > 0 and price > 0. The result should be a Map<String, Double> mapping symbol to total value. The current implementation uses a for loop with manual aggregation, but it is error-prone and difficult to parallelize. The team decides to refactor using the Stream API. The DataSource provides a Stream<Trade> trades(). The code must be efficient and handle large datasets. Which approach best meets these requirements?
Hard74Which TWO of the following are terminal operations on a stream? (Choose two.)
Easy75A data analytics platform processes user activity logs. Each log entry is a LogRecord with fields: userId (int), action (String), timestamp (long). The requirement is to find the top 3 most active users (by count of actions) in the last hour. The logs are stored in a List<LogRecord> logs. The current solution sorts all records by userId and counts manually, but it's slow. The team decides to use streams with parallel processing. Which code correctly identifies the top 3 users?
Medium76A developer needs to process a stream of integers and collect the results into a Map<Integer, List<Integer>> where keys are the integers themselves and values are lists containing the number and its square. Which collector should be used?
Hard77A developer writes the following code to print a list of strings in order: list.stream().map(s -> s.toUpperCase()).forEach(System.out::print). They want to parallelize the processing but must preserve the output order. Which change is correct and most appropriate?
Hard78A developer wants to compute the product of all even numbers in a stream of integers. Which of the following correctly implements this using streams?
Easy79Refer to the exhibit. A developer runs the code and gets an IllegalStateException on the second forEach. Which statement explains why?
Hard80Which THREE of the following are true about the Optional class? (Choose three.)
Hard81A team needs to process a large collection of orders to calculate total revenue per region. They decide to use parallel streams to improve performance. Which statement about using parallel streams for this task is true?
Medium82A developer uses a stateful lambda in a parallel stream. Which of the following is a potential consequence?
Medium83You are developing an online bookstore application. You have a list of Book objects, each with fields: String title, double price, and String genre. You need to generate a report that lists the total price of books in each genre, but only for genres where the average price is greater than $20.00. You are using Java 17 and streams. Which approach correctly accomplishes this task?
Easy84A financial application processes millions of transactions daily. The original code uses a for loop to aggregate transactions into a Map<Long, TransactionSummary> where the key is account ID. To improve performance, a developer refactors it using parallel streams: transactions.parallelStream() .collect(Collectors.toMap( Transaction::getAccountId, Function.identity(), (t1, t2) -> t1.merge(t2), // merging logic HashMap::new )); After deployment, they observe that the resulting map is smaller than expected and some transaction summaries are missing. Profiling shows the merge function is called infrequently, suggesting that the map is losing entries. What is the most likely cause and the correct fix?
Medium85A developer adds .peek(System.out::println) to a stream pipeline to debug, but no output is printed. What is the most likely reason?
Medium86Refer to the exhibit. What is the result?
Easy87A stream pipeline filters strings, sorts them, and returns the first match: .filter(s -> s.length() > 3).sorted().findFirst(). This is inefficient because sorted() processes all elements. Which alternative achieves the same result with better performance?
Hard88A developer writes: list.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); What is the result type and content?
Medium89Refer to the exhibit. What is the output?
MediumOther domains
All 1Z0-829 exam domains
Frequently asked questions
- What does the Working with Streams and Lambda Expressions domain cover on the 1Z0-829 exam?
- Working with Streams and Lambda Expressions questions test whether you can apply the concept in context, not just recognise a definition.
- How many questions are in this domain?
- This page lists all 89 Working with Streams and Lambda Expressions questions in the 1Z0-829 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
- What is the best way to practise this domain?
- Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
- Can I practise only Working with Streams and Lambda Expressions questions?
- Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.