Java Lambda - BiConsumer example








BiConsumer represents an operation that accepts two input arguments and returns no result.

The following example shows how to use BiConsumer.

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

    biConsumer.accept("java2s.com", " tutorials");
  }
}

The code above generates the following result.





Method

  1. BiConsumer accept
    Performs BiConsumer operation on the given arguments.
    biConsumer.accept("java2s.com", " tutorials");
  2. BiConsumer andThen
    BiConsumer andThen returns a composed BiConsumer that performs, in sequence, this operation followed by the after operation.
    biConsumer.andThen(biConsumer).accept("java2s.com", " tutorial");