Java Lambda - Function andThen example

Function andThen returns a composed function that first applies this function to its input, and then applies the after function to the result.


andThen has the following syntax.

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


The following example shows how to use andThen.

import java.util.function.Function;
//  www  .j  av  a 2  s .  c o  m
public class Main {

  public static void main(String[] args) {
    Function<Integer,String> converter = (i)-> Integer.toString(i);
    Function<String, Integer> reverse = (s)-> Integer.parseInt(s);

The code above generates the following result.