package com.home; import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Collectors; public class javaBiFunction { public static void main(String[] args) { // takes two Integers and return an Integer BiFunction func = (x1, x2) -> x1 + x2; Integer result = func.apply(2, 3); System.out.println(result); // 5 // take two Integers and return an Double BiFunction func2 = (x1, x2) -> Math.pow(x1, x2); Double result2 = func2.apply(2, 4); System.out.println(result2); // 16.0 // take two Integers and return a List BiFunction> func3 = (x1, x2) -> Arrays.asList(x1 + x2); List result3 = func3.apply(2, 3); System.out.println(result3); // Math.pow(a1, a2) returns Double BiFunction func1 = (a1, a2) -> Math.pow(a1, a2); // takes Double, returns String Function func2s = (input) -> "Result : " + String.valueOf(input); String results = func1.andThen(func2s).apply(2, 4); System.out.println(results); } }