集合方法
正常输入对象到集合里面,运用public使用类方法
import java.util.ArrayList;
public class test {
public static void main(String[] args) {
ArrayList<Student> list=new ArrayList<>();
//2.创建学生对象
Student s1=new Student("yanxiao1",1999);
Student s2=new Student("xiaoyan2",1000);
Student s3=new Student("yanxiao3",3999);
//3.添加对象到集合里面
list.add(s1);
list.add(s2);
list.add(s3);
ArrayList<Student> fff1=ff(list);
for (int i = 0; i < fff1.size(); i++) {
Student stuu=fff1.get(i);
System.out.println(stuu.getName()+" "+stuu.getXhao());
}
}
public static ArrayList<Student> ff(ArrayList<Student> list){
ArrayList<Student> list2=new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Student stu = list.get(i);
int p=stu.getXhao();
if(p<3000){
list2.add(stu);
}
}
return list2;
}
}
/*
yanxiao1 1999
xiaoyan2 1000
*/