Skip to content

Commit d4feaca

Browse files
committed
Added BiPredicate
1 parent 0653283 commit d4feaca

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.learn.functionalInterfaces;
2+
3+
import com.learn.data.Student;
4+
import com.learn.data.StudentDataBase;
5+
6+
import java.util.List;
7+
import java.util.function.BiConsumer;
8+
import java.util.function.BiPredicate;
9+
10+
public class BiPredicateExample {
11+
12+
/**
13+
* Same as Predicate, but BiPredicate accepts 2 parameters.
14+
*/
15+
static BiPredicate<Integer, Double> biPredicate = (gradeLevel, gpa) -> gradeLevel >= 2 && gpa >= 3.9;
16+
static BiConsumer<Integer, Double> biConsumer = (gradeLevel, gpa) -> System.out.println("GradeLevel = " + gradeLevel + " Gpa = " + gpa);
17+
18+
public static void main(String[] args) {
19+
20+
List<Student> students = StudentDataBase.getAllStudents();
21+
students.forEach(student -> {
22+
if (biPredicate.test(student.getGradeLevel(), student.getGpa())) {
23+
biConsumer.accept(student.getGradeLevel(), student.getGpa());
24+
}
25+
});
26+
27+
}
28+
}

0 commit comments

Comments
 (0)