-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest4.java
More file actions
42 lines (32 loc) · 1.18 KB
/
Copy pathTest4.java
File metadata and controls
42 lines (32 loc) · 1.18 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
package stream;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class Test4 {
public static void main(String[] args) {
List<Integer> arrList = new ArrayList<>();
arrList.add(5);
arrList.add(3);
arrList.add(8);
arrList.add(2);
int pr = arrList.stream().reduce((accumulator, element) ->accumulator*element).get();
System.out.println(pr);
List<Integer> list100 = new ArrayList<>();
Optional<Integer> o = list100.stream().reduce((accumulator, element) -> accumulator*element);
if (o.isPresent()) {
System.out.println(o.get());
} else {
System.out.println("Not Present");
}
int res = arrList.stream().reduce(1,(accumulator, element) ->accumulator*element);
System.out.println("_________________________________");
System.out.println(res);
List<String> list2 = new ArrayList<>();
list2.add("Privet");
list2.add("Kak dela?");
list2.add("Otlichno");
list2.add("Poka");
String res2 = list2.stream().reduce((a,e)->a + " " + e).get();
System.out.println(res2);
}
}