Java OCA OCP Practice Question 1723

Question

Which fills in the blank for this code to print 667788?

IntStream ints = IntStream.empty();
IntStream moreInts = IntStream.of(66, 77, 88);
Stream.of(ints, moreInts).___(x -> x).forEach(System.out::print);
A. flatMap
B. flatMapToInt
C. map
D. None of the above


B.

Note

Option A is incorrect because we are working with primitives rather than objects.

Option C compiles but outputs the stream references rather than the contents.

Option B is correct because it flattens the int primitives into one stream.




PreviousNext

Related