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

    biConsumer.accept("", " tutorials");

The code above generates the following result.


  1. BiConsumer accept
    Performs BiConsumer operation on the given arguments.
    biConsumer.accept("", " 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("", " tutorial");