Java Lambda - BiConsumer andThen example

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


andThen has the following syntax.

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


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

    biConsumer.andThen(biConsumer).accept("", " tutorial");

The code above generates the following result.