What is the result?

Given the code fragment:
UnaryOperator<Integer> uo1 = s -> s*2; line n1
List<Double> loanValues = Arrays.asList(1000.0, 2000.0);
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))
.forEach(s -> System.out.print(s + “ “));
What is the result?

Given the code fragment:
UnaryOperator<Integer> uo1 = s -> s*2; line n1
List<Double> loanValues = Arrays.asList(1000.0, 2000.0);
loanValues.stream()
.filter(lv -> lv >= 1500)
.map(lv -> uo1.apply(lv))
.forEach(s -> System.out.print(s + “ “));
What is the result?

A.
4000.0

B.
4000

C.
A compilation error occurs at line n1.

D.
A compilation error occurs at line n2.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


KashiHide

KashiHide

D.

But there is no line n2.
The line “.map(lv -> uo1.apply(lv))” should be line n2.

smh

smh

D.
A compilation error occurs at line n2.
and suppose line n2 is .map(…..

andrei

andrei

D
map(lv->uo1.apply(lv)) //line n2
fails to compile because the method apply(Integer) is not applicable for the argument (Double)