🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Streams in Depth: all 10 questions

Quiz: Java Streams in Depth · Question 8 of 10

Why use mapToInt(...).sum() instead of a Stream<Integer with reduce?

Why use mapToInt(...).sum() instead of a Stream<Integer> with reduce?

  1. A.reduce does not work on numbers
  2. B.sum() can be called many times on the same stream
  3. C.It changes the original list
  4. D.IntStream avoids boxing each number and gives sum, average and max directly
Answer & explanation

Correct answer: IntStream avoids boxing each number and gives sum, average and max directly

Primitive streams work on plain int values, which is simpler and avoids creating Integer objects.

Can you get the rest right without peeking?

Take the timed Quiz: Java Streams in Depth quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →