Given the code fragment:
Stream> iStr= Stream.of (
Arrays.asList ("1", "John"),
Arrays.asList ("2", null));
Stream<
What is the result?
Given the code fragment:
Stream> iStr= Stream.of (
Arrays.asList ("1", "John"),
Arrays.asList ("2", null));
Stream<
What is the result?
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.
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
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
D is the correct answer
D is correct since x.stream() return Stream of String and not int.
The correct answer is D.
D, Compilation error at line: Stream<<String> nInSt = iStr.flatMapToInt ((x) -> x.stream ());
answer is D , a compilation error