Java Lambda - DoubleConsumer andThen example








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

Syntax

andThen has the following syntax.

default DoubleConsumer andThen(DoubleConsumer after)

Example

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);
    d.andThen(d).andThen(d).accept(0.23);
  }
}

The code above generates the following result.