package com;
import java.util.ArrayList;
import java.util.List;
public class TestStudent {
public static void main(String[] args) {
List<Student> list = new ArrayList<Student>();
list.add(new Student(1,"zhangsan",56));
list.add(new Student(2,"mazi",43545));
list.add(new Student(4,"lisi",3));
for (int i = 0; i < list.size() ; i++) {
for (int j = 0; j < list.size()-i-1; j++) {
if(list.get(j).getAge()<list.get(j+1).getAge()){
Student stu=list.get(j);
list.set(j, list.get(j+1));
list.set(j+1, stu);
}
}
}
for (Student student : list) {
System.out.println(student.getAge()+"_-"+student.getId());
}
}
}
将集合中的学生的年龄升序排列
最新推荐文章于 2022-07-30 17:23:40 发布