Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 69

Given the code fragment:

UnaryOperator uo1 = s -> s*2; line n1

List 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?

    Correct Answer: D

    The code will have a compilation error at the line where the `.map(lv -> uo1.apply(lv))` method is used. The map method expects a function that takes a Double and returns a value, but the UnaryOperator uo1 is defined to take an Integer and return an Integer. This type mismatch causes a compilation error.

Discussion
InnovationOption: C

A compilation errors at Line 2, because uo1.apply() takes an integer but in map() we are passing a double

asdfjhfgjuaDCVOption: D

D is the correct answer

steefaandOption: D

Answer D is correct since .map(lv -> uo1.apply(lv)) line fails to compile as uo1 expects Integer, but Double is provided.

adnano1234Option: C

A compilation errors at Line 2 :The method map(Function<? super Double,? extends R>) in the type Stream<Double> is not applicable for the arguments (UnaryOperator<Integer>