DoubleConsumer andThen example

Description

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;
/* w  w  w.  j  a  v  a 2s.co  m*/
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.