-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathFunctionDemo.java
More file actions
27 lines (18 loc) · 934 Bytes
/
FunctionDemo.java
File metadata and controls
27 lines (18 loc) · 934 Bytes
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
package com.eazybytes.lambda;
import java.util.function.Function;
public class FunctionDemo {
public static void main(String[] args) {
Function<String, String> convertStr = input -> input.toUpperCase();
System.out.println(convertStr.apply("Eazy Bytes"));
Function<String, Integer> getStrLength = input -> input.length();
System.out.println(getStrLength.apply("Eazy Bytes"));
Function<String, String> sameValue = Function.identity();
System.out.println(sameValue.apply("Hi Madan"));
Function<Integer, Integer> doubleValue = num -> num * 2;
Function<Integer, Integer> addThree = num -> num + 3;
Function<Integer, Integer> output1 = doubleValue.andThen(addThree);
Function<Integer, Integer> output2 = doubleValue.compose(addThree);
System.out.println(output1.apply(5)); // 13
System.out.println(output2.apply(5)); // 16
}
}