Skip to content

Instantly share code, notes, and snippets.

@Yatharth0045
Last active April 7, 2019 16:12
Show Gist options
  • Save Yatharth0045/3cd41210bab21573aeb3c644cf626fb9 to your computer and use it in GitHub Desktop.
Save Yatharth0045/3cd41210bab21573aeb3c644cf626fb9 to your computer and use it in GitHub Desktop.
This program is to show the use of thenApply() method of completablefuture
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
class Test {
public static void main(String[] args) throws InterruptedException, ExecutionException {
CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> (int) (Math.random() * 10));
CompletableFuture<Boolean> completableFuture2 = completableFuture.thenApply(number -> number % 2 == 0);
System.out.println(completableFuture2.get() ? "Generated number is Even" : "Generated number is Odd");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment