Java Lambda - LongConsumer andThen example








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

Syntax

andThen has the following syntax.

default LongConsumer andThen(LongConsumer after)

Example

The following example shows how to use andThen.

import java.util.function.LongConsumer;

public class Main {

  public static void main(String[] args) {
    LongConsumer i = (l) -> System.out.println(l);;
    i.andThen(i).accept(Long.MAX_VALUE);
  }
}

The code above generates the following result.