Question 5
Back to Exercise
What is the output of the following Java program?
import java.util.concurrent.CompletableFuture;
public class Main {
public static void main(String[] args) {
String r = CompletableFuture.supplyAsync(() -> " learn java ")
.thenApply(String::strip)
.thenApply(String::toUpperCase)
.thenApply(s -> s.replace(' ', '-'))
.thenApply(s -> s + "!" + s.length())
.join();
System.out.println(r);
}
}
- A LEARN-JAVA!10 Correct
- B LEARN JAVA!10
- C LEARN-JAVA!14
- D LEARN-JAVA !14
Correct Answer: Option A
Each thenApply transforms the previous result, like map on a stream.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!