andThen

andThen is a method present in functional interfaces such as Function, Predicate and Consumer to allow you to chain the operations together.

You can pass it a second operation which is supposed to follow the first.

Definition

R andThen(Function<? super T, ? extends R> after) //R is a functional interface

Usage

Function<String, Integer> stringLength = s -> s.length();
Function<Integer, String> intToString = i -> String.valueOf(i);

Function<String, String> lengthToString = stringLength.andThen(intToString);
String result = lengthToString.apply("Hello"); // "5"