🎙 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 10 of 10

A list holds sentences. You want one stream of all their words. Which operation do you use?

A list holds sentences. You want one stream of all their words. Which operation do you use?

  1. A.map(s -> s.split(" "))
  2. B.filter(s -> s.contains(" "))
  3. C.peek(s -> s.split(" "))
  4. D.flatMap(s -> Arrays.stream(s.split(" ")))
Answer & explanation

Correct answer: flatMap(s -> Arrays.stream(s.split(" ")))

map would give a stream of arrays; flatMap turns each sentence into a stream of words and joins them into one.

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 →