-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLambdaTest.java
57 lines (46 loc) · 1.6 KB
/
LambdaTest.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.diyishuai.java8.lambda;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by Bruce on 16/8/8.
*/
public class LambdaTest {
public static void main(String[] args) {
System.out.println("foreach-less1.8");
//foreach-less1.8
List<String> strings = Arrays.asList("a","b","c","c");
for (String str:strings) {
System.out.println(str);
}
System.out.println("-------");
System.out.println("foreach 1.8");
//foreach 1.8
strings.forEach(str -> System.out.println(str));
// strings.forEach(str -> {System.out.println(str);});
System.out.println("===========");
//stream
strings.stream()
.distinct()
.limit(2)
.filter(str -> str == "a")
.forEach(str -> System.out.println(str));
System.out.println("===========");
System.out.println("peek");
strings.parallelStream()
.skip(2)
.forEach(str -> System.out.println(str));
System.out.println("===========");
distinctPrimary("12","23","12","23");
System.out.println("===========");
}
public static void distinctPrimary(String...numbers) {
List<String> strings = Arrays.asList(numbers);
List<Integer> collect = strings.parallelStream()
.map(e -> new Integer(e))
// .filter(e -> Primes.isPrime(e))
.distinct()
.collect(Collectors.toList());
System.out.println(collect);
}
}