How to use Function and BiFunction interfaces in lambda expression in Java?

The Function interface is a pre-defined functional interface that can be used as an assignment target for a lambda expression or method reference. It takes a single parameter and returns result by calling the apply() method. While the BiFunction interface is also a pre-defined functional interface that takes two parameters and returns a result. It is similar to the Function interface except it takes two parameters.


public interface Function<T, R>

public interface BiFunction<T, U, R>


import java.util.function.BiFunction;
import java.util.function.Function;

public class SampleFunctionBiFunctionTest {
   public static void main(String[] args) {
      Function<Integer, Integer> printNumber = a -> a*10;
      System.out.println("The number is: "+ printNumber.apply(10));

      BiFunction<Integer, Integer, Integer> add = (a, b) -> a+b;
      System.out.println("The addition of two numbers are: "+ add.apply(3,2));


The number is: 100
The addition of two numbers are: 5