202.
203.
numberChecker that accepts an integer value.
It is implemented
via a lambda expression that checks whether the input number is
greater than 20. Line 1 applies the Predicate on the value 10
while Line 2 applies the Predicate on the value 40. So, the
code prints the following output:
10 greater than 20:false
40 greater than 20:true
Which in–built functional interface would you use to
convert a String to uppercase?
Answer:
There is a built–in functional interface called UnaryOperator. It
accepts an argument of any data type and returns a result of the
same data type. It has a method called apply that operates on
the input value. So, you can use this to convert a String to
uppercase. The following code demonstrates this:
UnaryOperator
converter = str–>
str.toUpperCase();
System.out.println(converter.apply(“hello world”));
Here, the code creates a UnaryOperator implementation called
converter that operates on a String value. A lambda
expression is used that converts the String to uppercase. So, this
code prints the following output:
HELLO WORLD
Do'stlaringiz bilan baham: