forked from bjmashibing/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
58 lines (51 loc) · 1.65 KB
/
Test.java
File metadata and controls
58 lines (51 loc) · 1.65 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.mashibing.why3;
import com.mashibing.why.Student;
import com.mashibing.why2.StudentFilter;
import java.util.ArrayList;
/**
* @author: 马士兵教育
* @create: 2019-10-13 16:46
*/
public class Test {
public static void main(String[] args) {
ArrayList<Student> list = new ArrayList<Student>();
list.add(new Student("zhangsan",14,67));
list.add(new Student("lisi",13,89));
list.add(new Student("wangwu",15,97));
list.add(new Student("maliu",12,63));
list.add(new Student("zhaoqi",17,75));
getByFilter(list, new StudentFilter() {
@Override
public boolean compare(Student student) {
return student.getAge()>14;
}
});
getByFilter(list, new StudentFilter() {
@Override
public boolean compare(Student student) {
return student.getScore()>75;
}
});
System.out.println("-------------------");
getByFilter(list, new StudentFilter() {
@Override
public boolean compare(Student student) {
return student.getName().length()>5;
}
});
}
public static void getByFilter(ArrayList<Student> students, StudentFilter filter){
ArrayList<Student> list = new ArrayList<>();
for(Student student:students){
if(filter.compare(student)){
list.add(student);
}
}
printStudent(list);
}
public static void printStudent(ArrayList<Student> students){
for(Student student:students){
System.out.println(student);
}
}
}