Java Lambda - DoubleConsumer andThen example

DoubleConsumer andThen returns a composed DoubleConsumer that performs, in sequence, passed-in operation followed by the after operation.


andThen has the following syntax.

default DoubleConsumer andThen(DoubleConsumer after)


The following example shows how to use andThen.

import java.util.function.DoubleConsumer;

public class Main {
  public static void main(String[] args) {
    DoubleConsumer d = (x) -> System.out.println(x*x);

The code above generates the following result.