-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathLambda.java
35 lines (28 loc) · 884 Bytes
/
Lambda.java
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
package nextstep.fp;
import java.util.List;
public class Lambda {
public static void printAllOld(List<Integer> numbers) {
System.out.println("printAllOld");
for (int number : numbers) {
System.out.println(number);
}
}
public static void printAllLambda(List<Integer> numbers) {
System.out.println("printAllLambda");
numbers.forEach(System.out::println);
}
public static void runThread() {
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Hello from thread");
}
}).start();
}
public static int sumAll(List<Integer> numbers, SumStrategy sumStrategy) {
return numbers.stream()
.filter(sumStrategy::option)
.mapToInt(value -> value)
.sum();
}
}