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