W3Schools Learner's Blog

w3Schools programming knowledge summary website

div

4/25/2018

BiFunction Interface example

Interface BiFunction<T,U,R>

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Type Parameters:
T - the type of the first argument to the function
U - the type of the second argument to the function
R - the type of the result of the function

BiFunction Method:
  1. //Returns a composed function that first applies this function to its input, and then applies the after function to the result.
  2. default <V> BiFunction<T,U,V> andThen(Function<? super R,? extends V> after)
  3. //Applies this function to the given arguments.
  4. R apply(T t, U u)
BiFunction Example:
  1. import java.util.function.BiFunction;
  2. import java.util.function.Function;

  3. public class TestDemo {
  4.  public static void main(String[] args) {
  5.       BiFunction<String, String,String> biFunction = (x, y) -> {
  6.          return x+"==="+y;
  7.       };

  8.       Function<String,String> fun = x ->x + " after8";
  9.       System.out.println(biFunction.andThen(fun).apply("tpyyes.com ", " java8"));
  10.  }
  11. }
output:
  1. tpyyes.com === java8 after8

No comments:

Post a Comment

Note: only a member of this blog may post a comment.