- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiPredicateExample.java
More file actions
Latest commit
28 lines (21 loc) · 919 Bytes
/
Copy pathBiPredicateExample.java
File metadata and controls
28 lines (21 loc) · 919 Bytes
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
packagecom.learn.functionalInterfaces;
importcom.learn.data.Student;
importcom.learn.data.StudentDataBase;
importjava.util.List;
importjava.util.function.BiConsumer;
importjava.util.function.BiPredicate;
publicclassBiPredicateExample {
/**
* Same as Predicate, but BiPredicate accepts 2 parameters.
*/
staticBiPredicate<Integer, Double> biPredicate = (gradeLevel, gpa) -> gradeLevel >= 2 && gpa >= 3.9;
staticBiConsumer<Integer, Double> biConsumer = (gradeLevel, gpa) -> System.out.println("GradeLevel = " + gradeLevel + " Gpa = " + gpa);
publicstaticvoidmain(String[] args) {
List<Student> students = StudentDataBase.getAllStudents();
students.forEach(student -> {
if (biPredicate.test(student.getGradeLevel(), student.getGpa())) {
biConsumer.accept(student.getGradeLevel(), student.getGpa());
}
});
}
}