-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiFunctionExample.java
More file actions
31 lines (24 loc) · 1 KB
/
BiFunctionExample.java
File metadata and controls
31 lines (24 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package predefined_functional_interfaces.bi_functional_interfaces.bifunction;
/*
* Example demonstrating use of BiFunction and BiFunction chaining
*/
import java.util.function.BiFunction;
import java.util.function.Function;
public class BiFunctionExample {
public static void main(String[] args) {
BiFunction<Integer, Integer, Integer> multiply = (x, y) -> x * y;
Function<Integer, Integer> addTen = x -> x + 10;
BiFunction<Integer, Integer, Integer> combinedFunction = multiply.andThen(addTen);
int x = 5;
int y = 10;
System.out.printf("Multiplication of %d and %d : %d\n",x,y,multiply.apply(x,y));
System.out.printf("Increment %d by 10 : %d\n",x,addTen.apply(x));
System.out.printf("Multiplication of %d and %d and then increment the result by 10: %d\n", x,y, combinedFunction.apply(x, y));
}
}
/*
* Output:
* Multiplication of 5 and 10 : 50
* Increment 5 by 10 : 15
* Multiplication of 5 and 10 and then increment the result by 10: 60
*/