Chain of CompletableFutures in Java I am new to this CompletableFuture function in Java. I have the following code below that works fine but looks quite messy IMHO.

CompletableFuture&lt;String&gt; cf = CompletableFuture.completedFuture(isRQMRunning_3);

if(cf.isDone()) {
    System.out.println("Value- " + cf.get());
    cf = CompletableFuture.completedFuture(startRQM_4);

    if(cf.isDone()) {
        System.out.println("Value- " + cf.get());
        cf = CompletableFuture.completedFuture(pendingChangesStatus);

        if(cf.isDone()) {
            System.out.println("Value- " + cf.get());                   
            cf = CompletableFuture.completedFuture(acceptPendingChanges_8);

            if(cf.isDone()) {
                System.out.println("Value- " + cf.get());                       
                cf = CompletableFuture.completedFuture(loadWorkspace_5);

                if(cf.isDone()) {
                    System.out.println("Value- " + cf.get());
                    cf = CompletableFuture.completedFuture(acceptPendingChanges_8);

                    if(cf.isDone()) {
                        System.out.println("Value- " + cf.get());
                        cf = CompletableFuture.completedFuture(fixConflicts_9);

                        if(cf.isDone()) {
                            System.out.println("Value- " + cf.get());
                        }
                    }
                }
            }
        }
    }           
}


Is it possible to make that look a lot nicer/easier to read?
You have a lot of repetition in your code.
The only thing different with the 2 lines of code repeated over and over is the argument.

You could put all of these arguments into a list and iterate over them, running those 2 lines of code for each:

List&lt;String&gt; states = Arrays.asList(isRQMRunning_3, startRQM_4, 
  pendingChangesStatus, acceptPendingChanges_8, 
 loadWorkspace_5, acceptPendingChanges_8, fixConflicts_9);

for (String state : states)
{
    // Loop until array is complete
    CompletableFuture&lt;String&gt; cf = CompletableFuture.completedFuture(state);

    if (!cf.isDone())
    {
        break;
    }

    System.out.println("Value- " + cf.get());
}