01
import java.u;
02
import java.u;
03
import java.u;
04
import java.u;
05
import java.u;
06
import java.u;
07
import java.u;
08
09
/**
10
* @Auther: jack
11
* @Date: 2018/7/24 11:05
12
* @Description: jdk8 并行流处理
13
*/
14
public class Streamparallel {
15
public static void main(String[] args) {
16
//rangeClosed包含末尾数据
17
Long sum=LongS(1,10000000L).parallel().reduce(0,Long::sum);
18
Sy(sum);
19
20
//range不包含末尾节点
21
sum=LongS(1,10000000L).parallel().reduce(0,Long::sum);
22
Sy(sum);
23
24
//求和reduce()
25
Sy(1,2,3,4).reduce((sum2,item)->{
26
return sum2+item;
27
}).get());
28
Sy(1,2,3,4).reduce(Integer::sum).get());
29
30
//求最大值reduce()
31
Sy(1,2,3,4).reduce(100,(a,b)->Ma(a, b)));
32
Sy(1,2,3,4).reduce(Integer::max).get());
33
34
//去重distinct()
35
Sy("a", "b", "c", "d", "a", "b", "c")
36
.stream()
37
.distinct()
38
.collec())
39
);
40
41
//统计分组
42
Sy("apple", "apple", "banana",
43
"apple", "orange", "banana", "papaya")
44
.stream()
45
.collec(),Collec()))
46
);
47
48
//统计排序
49
Map<String,Long> sortMap=new LinkedHashMap<>();
50
Arrays.asList("apple", "apple", "banana", "apple", "orange", "banana", "papaya")
51
.stream()
52
.collec(),Collec()))
53
.entrySet()
54
.stream()
55
.sorted;String, Long>comparingByValue().reversed())
56
.forEachOrdered(e->(),e.getValue()));
57
Sy(sortMap);
58
}
59
}
运行结果: