forked from Rapter1990/JavaStreamAPIExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrecidateExample.java
More file actions
35 lines (22 loc) · 1.08 KB
/
PrecidateExample.java
File metadata and controls
35 lines (22 loc) · 1.08 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
package functionalexamples;
import studentdata.Student;
import studentdata.StudentDataBase;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public class PrecidateExample {
static Predicate<Student> p1 = (s) -> s.getGradeLevel()>=3;
static Predicate<Student> p2 = (s) -> s.getGpa()>=3.9;
public static void main(String[] args) {
getStudentsFilteredBy(p1.and(p2));
}
public static void getStudentsFilteredBy(Predicate<Student> predicatefilter) {
List<Student> students = StudentDataBase.getAllStudents();
students.stream().filter(predicatefilter).forEach(System.out::println);
/*
Student{name='Janet', gradeLevel=3, gpa=4.0, gender='female', activities=[swimming, gymnastics, aerobics], notebooks=12}
Student{name='Dave', gradeLevel=3, gpa=4.0, gender='male', activities=[swimming, gymnastics, soccer], notebooks=15}
Student{name='James', gradeLevel=4, gpa=3.9, gender='male', activities=[swimming, basketball, baseball, football], notebooks=22}
*/
}
}