CodeStudy.net
Toggle Menu
Home
Online Java Compiler
Tutorials
Java Tutorial
Python Tutorial
SQL Database Design
Blog
All Posts
Java Streams and Lambda Expressions
Evaluate your ability to use modern Java functional features.
1. Which of the following is a terminal stream operation?
filter
map
collect
flatMap
2. Select all functional interfaces from the following:
Runnable
Consumer
List
Predicate
String
3. A lambda expression can be used wherever a functional interface is expected.
True
False
4. What is the return type of the Stream.map() method? (Use generic notation)
5. Which lambda correctly represents a Consumer<Integer> that prints the integer?
(int x) -> { System.out.println(x); }
x -> println(x)
(x) -> System.out.println
Integer x -> print(x)
6. Which are intermediate stream operations?
filter
map
collect
forEach
sorted
7. Java Streams modify the original collection they are created from.
True
False
8. What method call converts a Stream<String> to a List<String> using Collectors?
9. What functional interface does Stream.filter() accept as an argument?
Predicate
Consumer
Function
Supplier
10. Which can be target types for a lambda expression?
Runnable
Callable<Integer>
String
List<String>
Comparator<String>
11. A lambda can access and modify non-final local variables from the enclosing scope.
True
False
12. Name the functional interface with a single abstract method 'apply' that takes one argument and returns a result.
13. What is the result of Stream.of(2, 4, 6, 8).count()?
4
[2, 4, 6, 8]
8
void
14. Select stateful intermediate stream operations:
filter
sorted
distinct
map
limit
15. Stream.forEach() returns a new Stream for further processing.
True
False
Reset
Answered 0 of 0 — 0 correct