-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPredicateStudentExample.java
More file actions
42 lines (31 loc) · 1.21 KB
/
PredicateStudentExample.java
File metadata and controls
42 lines (31 loc) · 1.21 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 com.learn.functionalInterfaces;
import com.learn.data.Student;
import com.learn.data.StudentDataBase;
import java.util.List;
import java.util.function.Predicate;
public class PredicateStudentExample {
static Predicate<Student> predicate1 = (student) -> student.getGradeLevel() >= 3;
static Predicate<Student> predicate2 = (student) -> student.getGpa() >= 3.9;
public static void filterStudentByGradeLevel() {
System.out.println("filterStudentByGradeLevel()::invoked");
List<Student> students = StudentDataBase.getAllStudents();
students.forEach(student -> {
if (predicate1.test(student)) {
System.out.println(student);
}
});
}
public static void filterStudentByGradeLevelAndGpa() {
System.out.println("filterStudentByGradeLevelAndGpa()::invoked");
List<Student> students = StudentDataBase.getAllStudents();
students.forEach(student -> {
if (predicate1.and(predicate2).test(student)) {
System.out.println(student);
}
});
}
public static void main(String[] args) {
filterStudentByGradeLevel();
filterStudentByGradeLevelAndGpa();
}
}