Log in
Sign up for FREE
arrow_back
Library

Java Lambda & Streams Quiz

star
star
star
star
star
Last updated over 2 years ago
15 questions
Single/Multiple choise:
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Untitled Section
Question 1
1.

Question 2
2.

Question 3
3.

Question 4
4.

Question 5
5.

Question 6
6.

Question 7
7.

Question 8
8.

Question 9
9.

Question 10
10.

Question 11
11.

Question 12
12.

Question 13
13.

Question 14
14.

Question 15
15.

What is the syntax for a lambda expression in Java?
{params} -> expression
(params) -> expression
(params) => expression
{params} => expression
Which of the following functional interfaces represents a function that takes an argument and returns a result?
Consumer
Supplier
Function
BiConsumer
What is the purpose of the anyMatch() method in Java streams?
It returns true if all elements of the stream match the given predicate.
It returns true if any element of the stream matches the given predicate.
It returns true if none of the elements of the stream match the given predicate.
It returns true if the stream is empty.
Which of the following terminal operations does not return a value in Java streams?
forEach()
collect()
map()
reduce()
What does the sorted() method do in Java streams?
It shuffles the elements of the stream randomly.
It sorts the elements of the stream in reverse order.
It sorts the elements of the stream in natural order.
It doesn't have any effect on the order of elements in the stream.
What is the output of the following Java stream operation?
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
int result = numbers.stream()
.filter(x -> x % 2 == 0)
.mapToInt(x -> x)
.sum();
System.out.println(result);
6
9
10
15
What does the collect() terminal operation do in Java streams?
Transforms each element in the stream
Reduces the elements of the stream to a single value
Collects the elements of the stream into a collection
Checks if any element matches a given condition
Which functional interface represents a function that takes an argument and returns a boolean result?
Consumer
Predicate
Supplier
Function
Which terminal operation is used to find the maximum element in a stream?
max()
findMax()
maximum()
findFirst()
Terminal short-circuiting operations are:
findAny()
findFirst()
anyMatch(Predicate)
allMatch(Predicate)
noneMatch(Predicate)
Which of the following terminal operations in Java streams can produce results of type Optional?
findFirst()
findAny()
max(Comparator)
min(Comparator)
Which of the following Java stream intermediate operations are stateful?
map()
sorted()
filter()
distinct()
Which of the following Java stream terminal operations are stateless?
map()
filter()
distinct()
sorted()
flatMap()
What is the output of the following Java stream operation?
List<String> words = Arrays.asList("apple", "orange", "grape", "melon", "banana",);
String result = words.stream()
.filter(s -> s.length() > 5)
.findFirst()
.orElse("No word found");
"No word found"
"apple"
"orange"
"banana"
What is the value of result after executing this code?
Function<Integer, Integer> addTwo = x -> x + 2;
int result = addTwo.apply(5);
5
7
10
Compilation error