-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathO7Reduce.java
More file actions
36 lines (24 loc) · 876 Bytes
/
O7Reduce.java
File metadata and controls
36 lines (24 loc) · 876 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
28
29
30
31
32
33
34
35
36
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public class O7Reduce {
public static void main(String[] args) {
List<Integer> tall = Arrays.asList(4, 3, 1, 8, 100, 55, 29, 111);
// Average, Sum, Min, Max, Count, Reduce
System.out.println(tall.stream().count());
System.out.println(tall.stream()
.mapToInt(i -> i)
.average()
.getAsDouble());
System.out.println(tall.stream()
.max((a, b) -> a.compareTo(b))
.get());
System.out.println(tall.stream()
.min(Integer::compare)
.get());
System.out.println(tall.stream()
.reduce((sum, i) -> sum * i));
System.out.println(tall.stream()
.reduce((sum, i) -> sum * i));
}
}