-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx2_Student.java
More file actions
40 lines (31 loc) · 1.23 KB
/
Copy pathEx2_Student.java
File metadata and controls
40 lines (31 loc) · 1.23 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
package lambda.lambda5.mystream;
import lambda.lambda5.filter.GenericFilter;
import lambda.lambda5.map.GenericMapper;
import java.util.ArrayList;
import java.util.List;
import static lambda.lambda5.filter.GenericFilter.filter;
import static lambda.lambda5.map.GenericMapper.map;
public class Ex2_Student {
public static void main(String[] args) {
List<Student> students = List.of(
new Student("Apple", 100),
new Student("Banana", 80),
new Student("Berry", 50),
new Student("Tomato", 40)
);
List<String> directResult = direct(students);
System.out.println("directResult = " + directResult);
List<String> lambdaResult = lambda(students);
System.out.println("lambdaResult = " + lambdaResult);
}
private static List<String> lambda(List<Student> students) {
return map(filter(students, student -> student.getScore() >= 80), student -> student.getName());
}
private static List<String> direct(List<Student> students) {
List<String> ans = new ArrayList<>();
for (Student student : students) {
if(student.getScore() >= 80) ans.add(student.getName());
}
return ans;
}
}