Skip to content
Sharp

Concurrency basics · interview question

Which of the following best describes the behavior of CompletableFuture.anyOf()?

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

Correct answer

B. Completes when any provided future completes.

Why

CompletableFuture.anyOf() completes when any of the provided futures complete, regardless of whether it's a completion or an exception. It's useful when you want to proceed as soon as a single result is available.

Test yourself on Concurrency basics

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

Start free test
All Concurrency basics questions →