Java OCA OCP Practice Question 1729

Question

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. None
  • B. One
  • C. Two
  • D. Three


A.

Note

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.




PreviousNext

Related