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

Given the code fragment:

Stream> iStr= Stream.of (

Arrays.asList ("1", "John"),

Arrays.asList ("2", null));

Stream< nInSt = iStr.flatMapToInt ((x) -> x.stream ()); nInSt.forEach (System.out :: print);

What is the result?

    Correct Answer: D

    The code will not compile because of the use of flatMapToInt instead of flatMap. The method flatMapToInt expects a function that returns an IntStream, but x.stream() returns a Stream<String>. Thus, a compilation error occurs due to the mismatched types.

Discussion
InnovationOption: D

D, a compile error occurs. if we change "Stream<String> nInSt = iStr.flatMapToInt((x) -> x.stream ());" to "Stream<String> nInSt = iStr.flatMap((x) -> x.stream ());" then the output is 1John2null

Shad657Option: D

Compilation error: incompatible types: bad return type in lambda expression Stream<String> nInSt = iStr.flatMapToInt((x) -> x.stream()); ^ Stream<String> cannot be converted to IntStream

asdfjhfgjuaDCVOption: D

D is the correct answer

steefaandOption: D

D is correct since x.stream() return Stream of String and not int.

r1muka5Option: D

The correct answer is D.

YasinGaberOption: D

D, Compilation error at line: Stream<<String> nInSt = iStr.flatMapToInt ((x) -> x.stream ());

M_JawadOption: D

answer is D , a compilation error