Practice 1Z0-829 Working with Streams and Lambda Expressions questions with full explanations on every answer.
Start practicing
Working with Streams and Lambda Expressions — choose a session length
Free · No account required
Click any question to see the full explanation and answer options, or start a focused practice session above.
A 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?
2A 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?
3A 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?
4A 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?
5Which statement about the Stream API is true?
6Given: 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?
7A developer wants to find the longest word in a list of strings. Which stream operation should be used?
8What 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);
9Which 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
10Which 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.
11Which THREE statements about lambda expressions are true? (Choose three.) 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.
12A 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?
13A 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?
14A 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?
15Which TWO are correct about parallel streams in Java? (Choose TWO.)
16You 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?
17A 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?
18Which TWO statements are true about the Stream API and lambda expressions in Java 17?
19The code fails to compile. What is the reason?
20Order the steps to properly implement the Singleton pattern with lazy initialization in Java.
21Match each exception class to its category (checked/unchecked).
22A developer wants to count how many strings in a list have length greater than 5. Which is the correct implementation?
23A 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?
24Given 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?
25Which functional interface is most appropriate for a lambda that takes a String and returns nothing?
26A developer wants to create a stream that repeatedly generates random integers. Which method should be used?
27A 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?
28Which code will successfully produce an Optional<Integer> that contains the maximum value from a list of integers?
29A developer writes: list.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); What is the result type and content?
30Given: 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?
31Which TWO of the following are terminal operations on a stream? (Choose two.)
32Which TWO statements about method references are true? (Choose two.)
33Which THREE of the following are valid ways to create an infinite stream? (Choose three.)
34What is the result of executing this code?
35What is the output?
36What is the output?
37A 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?
38A 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?
39A 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?
40Which TWO are valid ways to obtain a Stream from a List<String> named 'list'? (Choose two.)
41Which THREE are valid method references in Java 17? (Choose three.)
42Which TWO are terminal operations on the Stream interface? (Choose two.)
43What is the output of the code above?
44What is the output?
45Assuming the code runs in a multithreaded environment, which statement best describes the behavior?
46A developer needs to concatenate two Stream<String> into one. Which approach is most idiomatic?
47A stream pipeline uses groupingBy with a downstream collector to count occurrences. The developer expects a Map<Integer, Long> but gets a compilation error. Which is the correct way to write the collector?
48A developer wants to collect elements from a stream into an immutable List. Which collector should be used?
49A stream pipeline uses the peek method for debugging. Which statement about peek is correct?
50A 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?
51A 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?
52A 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?
53A 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?
54A 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?
55A lambda that takes a String and returns its length is assigned to which functional interface?
56A developer uses a stateful lambda in a parallel stream. Which of the following is a potential consequence?
57Given a list of strings, which of the following will produce a Map<String, Long> counting the occurrences of each string?
58Which of the following is a terminal operation of the Stream API?
59A developer adds .peek(System.out::println) to a stream pipeline to debug, but no output is printed. What is the most likely reason?
60Which of the following lambda expressions is syntactically invalid?
61Which TWO of the following are characteristics of a well-designed lambda expression? (Choose two.)
62Which THREE of the following are valid ways to create a Stream<String>? (Choose three.)
63Which THREE of the following are true about the Optional class? (Choose three.)
64Refer to the exhibit. What is the result?
65Refer to the exhibit. What is the output?
66A 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?
67A developer wants to compute the product of all even numbers in a stream of integers. Which of the following correctly implements this using streams?
68A 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?
69A 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?
70Which two statements are true about the peek method of the Stream API? (Choose two.)
71Which three are terminal operations of the Stream interface? (Choose three.)
72A 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?
73A 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?
74A 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?
75A 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?
76A 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?
77A 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?
78A 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?
79Which two statements about the Stream API are true? (Choose two.)
80Refer to the exhibit. What is the output?
81A 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?
82Refer to the exhibit. A developer runs the code and gets an IllegalStateException on the second forEach. Which statement explains why?
83Refer to the exhibit. What is the output?
84Refer to the exhibit. What is the output?
85Refer to the exhibit. What is the output?
86Refer to the exhibit. What is the output?
The Working with Streams and Lambda Expressions domain covers the key concepts tested in this area of the 1Z0-829 exam blueprint published by Oracle. Courseiva provides free domain-focused practice, mock exams, missed-question review, and readiness tracking across all 1Z0-829 domains — no account required.
The Courseiva 1Z0-829 question bank contains 86 questions in the Working with Streams and Lambda Expressions domain. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Working with Streams and Lambda Expressions domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included