Java Lambda - BiFunction andThen example








Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.

Syntax

andThen has the following syntax.

default <V> BiFunction<T,U,V> andThen(Function<? super R,? extends V> after)

Example

The following example shows how to use andThen.

import java.util.function.BiFunction;
import java.util.function.Function;
//ww w  . j  ava 2 s. c om
public class Main {
  public static void main(String[] args) {
    BiFunction<String, String,String> bi = (x, y) -> {      
      return x + y;
    };
    Function<String,String> f = x-> x+" new";
    
    System.out.println(bi.andThen(f).andThen(f).apply("java2s.com", " tutorial"));
  }
}

The code above generates the following result.