Use Java object and primitive Streams, including lambda expressions implementing functional interfaces, to create, filter, transform, process, and sort data.
1. The correct answers are B and D.
Explanation:
abstract
methods.
static
methods.
@FunctionalInterface
annotation is mandatory to declare a functional interface.
@FunctionalInterface
annotation is not mandatory; it is only a marker to indicate that the interface is intended to be a functional interface. An interface can be a functional interface without this annotation as long as it has exactly one abstract method.2. The correct answer is A.
Explanation:
(s1, s2) -> s1.compareTo(s2)
Comparator<String>
interface. It uses the correct syntax for a lambda expression, with parameters enclosed in parentheses and a single expression for the body.(String s1, s2) -> s1.compareTo(s2)
(String s1, String s2)
.s1, s2 -> s1.compareTo(s2)
(s1, s2)
.(s1, s2) -> return s1.compareTo(s2);
(s1, s2) -> { s1.compareTo(s2); }
(s1, s2) -> { return s1.compareTo(s2); }
.3. The correct answer is B.
Explanation:
java.util.function.Function
Function
represents a function that takes one argument and produces a result.java.util.function.BiFunction
BiFunction
represents a function that takes two arguments and produces a result.java.util.function.Supplier
Supplier
represents a function that takes no arguments and produces a result.java.util.function.Consumer
Consumer
represents a function that takes one argument and does not produce a result.java.util.function.Predicate
Predicate
represents a function that takes one argument and returns a boolean
value.4. The correct answer is A.
Explanation:
13
combinedFunction
first multiplies 5 by 2 to get 10, then adds 3, resulting in 13.16
10
11
8
5. The correct answer is C.
Explanation:
String::valueOf
String::valueOf
converts an integer to a string, not a string to an integer.Integer::valueOf
Integer::valueOf
returns an Integer
object, while the lambda returns an int
.Integer::parseInt
Integer::parseInt
is a method reference that matches the lambda expression str -> Integer.parseInt(str)
which converts a string to an integer.String::parseInt
String
class does not have a parseInt
method.Integer::toString
Integer::toString
converts an integer to a string, not a string to an integer.Do you like what you read? Would you consider?
Do you have a problem or something to say?