Java SE API

CompletionStage.thenApply()

Transform a successful stage value.

Formal Syntax & Structure

java syntaxjava
<U> CompletionStage<U> thenApply(Function<? super T, ? extends U> fn)

Parameters & Attributes

NameTypeDescription
fnFunction<? super T, ? extends U>Transform the successful value

Working Example

Example Snippetjava
import java.util.concurrent.*;import java.util.concurrent.atomic.*;import java.util.concurrent.locks.*;public class Main {
    public static void main(String[] args) throws Exception {        CompletableFuture<Integer> price = CompletableFuture.completedFuture(120);        CompletionStage<Integer> total = price.thenApply(p -> p + 30);        System.out.println(total.toCompletableFuture().join());    }}
Java Reference