-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.java
More file actions
67 lines (45 loc) · 1.8 KB
/
Copy pathFunctions.java
File metadata and controls
67 lines (45 loc) · 1.8 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package function;
import java.util.List;
import java.util.function.*;
public class Functions {
public static void main(String[] args) {
String a = "Effective Java";
String b = "Gang of four";
String sizeTest = "abcdef"; // very creative
List<String> list = List.of(
"potato",
"banana",
"apples",
"mango"
);
System.out.println("Function \t-> \t" + returnLen.apply("is this working?"));
System.out.println("BiFunction \t-> \t" + returnCombinedLen.apply(a, b));
System.out.println("Predicate \t-> \t" + sizeBelowTen.test(sizeTest));
System.out.println("Dobule rand \t-> \t" + giveMeRandom.getAsDouble());
addNameAtEnd.accept(list);
System.out.println("Consumer \t-> \t" + list);
modify.accept(list);
System.out.println("Consumer mod \t-> \t" + list);
System.out.println("\nDoubleFunctional");
System.out.println(doubleFunc.apply(10));
//
}
static Function<String, Integer> returnLen = x -> x.length();
static BiFunction<String, String, Integer> returnCombinedLen =
(x, y) -> x.length() + y.length();
static Predicate<String> sizeBelowTen = word -> word.length() < 10;
static DoubleSupplier giveMeRandom = Math::random;
static Consumer<List<String>> addNameAtEnd = list -> // assignment
{
for(String each : list) {
each += " X";
System.out.println(each);
}
};
static Consumer<List<String>> modify = list ->
{
// for(int i = 0; i < list.size(); i++)
// list.set(i, list.get(i) + " X");
};
static DoubleFunction<Double> doubleFunc = x -> x + 0.23;
}