Repository navigation
Expand file tree
/
Copy pathDemo2.java
More file actions
63 lines (47 loc) · 1.59 KB
/
Copy pathDemo2.java
File metadata and controls
63 lines (47 loc) · 1.59 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
import java.util.*;
public class Demo2 {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>(List.of(1, 13, 11, 9, 24));
// List<Integer> list2 = list.stream()
// .map(x -> x + 1)
// .toList();
// System.out.println(list2);
// list.remove(0);
// System.out.println(list2);
// List<Integer> list3 = list.stream()
// .map(x -> x + 1)
// .collect(Collectors.toList());
// System.out.println(list3);
// Set<Integer> set = list.stream()
// .map(x -> x + 1)
// .collect(Collectors.toSet());
// System.out.println(set);
// Integer sum = list.stream()
// .reduce(0, (a, b) -> a + b);
// System.out.println(sum);
// long num = list.stream()
// .filter(x -> x > 10)
// .count();
// Optional<Integer> num = list.stream()
// .filter(x -> x > 10)
// .findFirst();
// Optional<Integer> num = list.stream()
// .filter(x -> x > 10)
// .findAny();
// System.out.println(num.get());
// boolean b = list.stream()
// .filter(x -> x > 10)
// . allMatch(x -> x % 2 == 0);
// System.out.println(b);
int sum = list.stream()
.filter(x -> x > 10)
.mapToInt(x -> x)
.sum();
System.out.println(sum);
OptionalInt max = list.stream()
.filter(x -> x > 10)
.mapToInt(x -> x)
.max();
System.out.println(max.getAsInt());
}
}