Last Updated: December 6, 2025
29 quizzes
Use a lambda-compatible method to check if any element in the stream matches the condition.
boolean hasLongName = names.stream().(name -> name.length() > 10);Click an option to fill the blank:
Use a method reference to sort users by their natural ordering using a Comparator factory.
users.sort(Comparator.(User::getName));Click an option to fill the blank:
Create an Optional from a value that might be null.
Optional<String> safeEmail = Optional.(user.getEmail());Click an option to fill the blank:
Which statement about lambda expressions in Java is true?
Which method reference form refers to an instance method of an existing object?
Which statement about Java Streams is correct?
Which pair correctly describes intermediate vs terminal operations?
Which stream operation is a terminal operation?
Which Collector would you use to group users by their city?
When might a parallel stream be a bad choice?
Which Optional method allows you to provide a default value if the Optional is empty?
What does Stream.flatMap typically help you achieve?
Which terminal operation would you use to check if no elements in a stream satisfy a condition?
Which code correctly uses a constructor reference with streams?
Order the steps to filter and collect a list of emails from active users using streams.
Drag and drop to reorder, or use the arrows.
Order the steps to safely handle a possibly null address field using Optional.
Drag and drop to reorder, or use the arrows.
What is the output of this lambda-based computation?
1import java.util.List;
2
3public class Test {
4 public static void main(String[] args) {
5 List<Integer> nums = List.of(1, 2, 3, 4);
6 int result = nums.stream()
7 .filter(n -> n % 2 == 0)
8 .map(n -> n * n)
9 .reduce(0, Integer::sum);
10 System.out.println(result);
11 }
12}What does this method reference and Optional pipeline print?
1import java.util.Optional;
2
3public class Test {
4 public static void main(String[] args) {
5 Optional<String> name = Optional.of("alice");
6 String result = name.map(String::toUpperCase)
7 .orElse("UNKNOWN");
8 System.out.println(result);
9 }
10}What single line is printed by this code using Stream.generate and limit?
1import java.util.stream.Stream;
2
3public class Test {
4 public static void main(String[] args) {
5 long count = Stream.generate(() -> "x")
6 .limit(5)
7 .count();
8 System.out.println(count);
9 }
10}What does this Collectors.joining operation print?
1import java.util.List;
2import java.util.stream.Collectors;
3
4public class Test {
5 public static void main(String[] args) {
6 List<String> tags = List.of("java", "streams", "lambda");
7 String joined = tags.stream()
8 .map(String::toUpperCase)
9 .collect(Collectors.joining(";"));
10 System.out.println(joined);
11 }
12}What is printed when using a parallel stream with sum?
1import java.util.stream.IntStream;
2
3public class Test {
4 public static void main(String[] args) {
5 int sum = IntStream.rangeClosed(1, 4)
6 .parallel()
7 .sum();
8 System.out.println(sum);
9 }
10}Find the bug in this code that maps a list of names to their lengths using method references.
Click on the line(s) that contain the bug.
import java.util.List;import java.util.stream.Collectors; public class NameLengths { public static List<Integer> lengths(List<String> names) { return names.stream() .map(String::new) .collect(Collectors.toList()); }}Identify the bug in this code that uses Optional to get the first even number.
Click on the line(s) that contain the bug.
import java.util.List;import java.util.Optional; public class FirstEven { public static int firstEvenOrDefault(List<Integer> numbers) { Optional<Integer> opt = numbers.stream() .filter(n -> n % 2 == 0) .findFirst(); return opt.get(); }}Match the stream-related concepts with their descriptions.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match the Optional methods with their behavior.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to filter active users and collect their usernames into a List.
import java.util.List;import java.util.stream.Collectors;class User { private boolean active; private String username; public boolean isActive() { return active; } public String getUsername() { return username; }}public class Example { public List<String> activeUsernames(List<User> users) { return users.stream() .(User::isActive) .(User::getUsername) .collect(Collectors.toList()); }}Click an option to fill blank 1:
Complete the code to safely get the uppercased city from a possibly null address.
import java.util.Optional;class Address { private String city; public String getCity() { return city; }}public class Example { public String cityOrUnknown(Address address) { return Optional.(address) .(Address::getCity) .map(String::toUpperCase) .orElse("UNKNOWN"); }}Click an option to fill blank 1:
Click the line that is most likely to cause a performance issue when used inside a parallel stream pipeline.
Click on the line to select.
import java.util.List; public class Demo { public void logInParallel(List<String> messages) { messages.parallelStream() .forEach(msg -> { System.out.println(msg); }); }}Click the line that can throw a NullPointerException when using method references.
Click on the line to select.
import java.util.List; public class Demo { public void printNames(List<String> names) { names.stream() .map(String::toUpperCase) .forEach(System.out::println); }}