← 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?
- A.map(s -> s.split(" "))
- B.filter(s -> s.contains(" "))
- C.peek(s -> s.split(" "))
- 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 →