-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntro_6.java
More file actions
52 lines (44 loc) · 1.42 KB
/
Copy pathIntro_6.java
File metadata and controls
52 lines (44 loc) · 1.42 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
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.IntStream;
public class Intro_6 {
public static void main(String[] args) {
System.out.println("Java Streams");
IntStream stream = IntStream.range(1, 10);
System.out.println("\n Stream: " + element(stream));
}
private static List<Integer> element(IntStream list) {
return list.boxed()
.filter(predicate_1.and(predicate_2))
.map(function_1)
.toList();
}
private static Predicate<Integer> predicate_1 = new Predicate<Integer>() {
@Override
public boolean test(Integer t) {
System.out.println("Predicate one: " + t);
if (t > 3) {
return true;
}
return false;
}
};
private static Predicate<Integer> predicate_2 = new Predicate<Integer>() {
@Override
public boolean test(Integer t) {
System.out.println("Predicate two: " + t);
if (t < 8) {
return true;
}
return false;
}
};
private static Function<Integer, Integer> function_1 = new Function<Integer, Integer>() {
@Override
public Integer apply(Integer t) {
System.out.println("Function: " + t);
return t * 2;
}
};
}