Skip to content
Sharp

Concurrency basics · interview question

In which scenario would you use.thenCompose() over.thenApply() in CompletableFuture?

Multiple choiceMediumchapter-15-curatedpremiumconcurrencycompletablefuture
Choose one answer
Answer and explanation

Correct answer

A. When you want to return another CompletableFuture.

Why

.thenCompose() is used when a function returns another CompletableFuture, allowing you to flatten nested futures into a single asynchronous computation, unlike.thenApply(), which transforms the result without flattening.

Test yourself on Concurrency basics

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

Start free test
All Concurrency basics questions →