What is the result?

Given the code fragment:
Stream<List<String>> iStr= Stream.of (
Arrays.asList (“1”, “John”),
Arrays.asList (“2”, null)0;
Stream<<String> nInSt = iStr.flatMapToInt ((x) -> x.stream ());
nInSt.forEach (System.out :: print);
What is the result?

Given the code fragment:
Stream<List<String>> iStr= Stream.of (
Arrays.asList (“1”, “John”),
Arrays.asList (“2”, null)0;
Stream<<String> nInSt = iStr.flatMapToInt ((x) -> x.stream ());
nInSt.forEach (System.out :: print);
What is the result?

A.
1John2null

B.
12

C.
A NullPointerException is thrown at run time.

D.
A compilation error occurs.



Leave a Reply 4

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


CompileTester

CompileTester

D

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

Berti John

Berti John

D. is correct