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.


andThen has the following syntax.

default IntConsumer andThen(IntConsumer after)


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);


The code above generates the following result.