Skip to content
Sharp

Project Reactor · interview question

Given the following code snippet, what is the expected output order? Flux.just(1, 2, 3).flatMap(i -> Mono.just(i * 2)).subscribe(System.out::println);?

Multiple choiceMediumchapter-19-curatedpremiumproject-reactorfunctional-pipelines-flatmap
java
Flux.just(1, 2, 3)
  .flatMap(i -> Mono.just(i * 2))
  .subscribe(System.out::println);
Choose one answer
Answer and explanation

Correct answer

B. The output order is not guaranteed.

Why

Using flatMap() in a reactive pipeline may result in out-of-order processing due to its asynchronous nature, hence the output order is not guaranteed.

Test yourself on Project Reactor

A free test with instant, explained results. No account needed.

Start free test
All Project Reactor questions →