Java Lambda - IntConsumer andThen example








Returns a composed IntConsumer that performs, in sequence, this operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the after operation will not be performed.

Syntax

andThen has the following syntax.

default IntConsumer andThen(IntConsumer after)

Example

The following example shows how to use andThen.

import java.util.function.IntConsumer;
/*  ww w  . j a  va  2s.  com*/
public class Main {

  public static void main(String[] args) {
    IntConsumer ic = (x)->System.out.println(x);
    
    ic.andThen(ic).accept(3);

  }
}

The code above generates the following result.