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
47 lines (43 loc) · 1.31 KB
/
Test.java
File metadata and controls
47 lines (43 loc) · 1.31 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
package com.mashibing.why;
import java.util.ArrayList;
/**
* @author: 马士兵教育
* @create: 2019-10-13 16:33
*/
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));
//查找年龄大于14的学生
findByAge(list);
System.out.println("---------------------");
//查找分数大于75的学生
findByScore(list);
}
public static void findByAge(ArrayList<Student> students){
ArrayList<Student> list =new ArrayList<>();
for(Student stu:students){
if(stu.getAge()>14){
list.add(stu);
}
}
for(Student student :list){
System.out.println(student);
}
}
public static void findByScore(ArrayList<Student> students){
ArrayList<Student> list =new ArrayList<>();
for(Student stu:students){
if(stu.getScore()>75){
list.add(stu);
}
}
for(Student student :list){
System.out.println(student);
}
}
}