Java Lambda - BiConsumer andThen example








BiConsumer andThen returns a composed BiConsumer that performs, in sequence, this operation followed by the after operation.

Syntax

andThen has the following syntax.

default BiConsumer<T,U> andThen(BiConsumer<? super T,? super U> after)

Example

The following example shows how to use andThen.

import java.util.function.BiConsumer;
/* w w  w  .  j  a v  a  2 s  . co m*/
public class Main {
  public static void main(String[] args) {
    BiConsumer<String, String> biConsumer = (x, y) -> {
      System.out.println(x);
      System.out.println(y);
    };

    biConsumer.andThen(biConsumer).accept("java2s.com", " tutorial");
  }
}

The code above generates the following result.