How many of the following can fill in the blank to have the code print the single digit 9?
LongStream stream = LongStream.of(9); stream.___(p -> p).forEach(System.out::print);
I. mapToDouble II. mapToInt III. mapToLong
A.
The mapToDouble()
method compiles.
It converts 9 into 9.0 rather than the single digit 9.
The mapToInt()
method does not compile because a long cannot be converted into an int without casting.
The mapToLong()
method is not available on LongStream so it does not compile.
It is available on DoubleStream, IntStream, and Stream implementations.
Since none of the options outputs the single digit 9, Option A is correct.