Reactive Streams · interview question
When using Project Reactor, how does the 'map' operator differ from 'flatMap'?
Multiple choiceMediumchapter-19-curatedpremiumreactive-streamsnon-blocking-i-o-event-loops
Flux.just(1, 2, 3).map(i -> i * 2).subscribe(System.out::println);Answer and explanation
Correct answer
C. Map transforms data items individually, flatMap combines multiple streams.
Why
The 'map' operator applies a transformation to each item in a stream individually, while 'flatMap' can be used to flatten multiple streams into a single stream.
Test yourself on Reactive Streams
A free test with instant, explained results. No account needed.
More Reactive Streams questions
- Why is it essential to avoid legacy JDBC in a reactive WebFlux application?
- What would be the effect of calling request(Long.MAX_VALUE) on a Subscription?
- Why does a Subscriber in the Reactive Streams specification matter in this design?
- How would you explain a key difference between WebFlux and virtual threads for handling concurrency in an interview?
- Which method in a Subscriber handles the completion signal from a Publisher?
- How do Virtual Threads in Project Loom aim to simplify concurrent programming compared to WebFlux?