package mytool;
import java.util.ArrayList;
import java.util.List;
public class Paixu {
public static void main(String[] args) {
List<User> list=new ArrayList<>();
User u=new User();
u.setName("张三");
u.setAge(19);
User u2=new User();
u2.setName("李四");
u2.setAge(20);
User u3=new User();
u3.setName("王五");
u3.setAge(18);
User u4=new User();
u4.setName("王路");
u4.setAge(8);
User u5=new User();
u5.setName("王啊");
u5.setAge(30);
list.add(u);
list.add(u2);
list.add(u3);
list.add(u4);
list.add(u5);
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < list.size()-1; j++) {
if(list.get(j).getAge()>list.get(j+1).getAge()){
User use=list.get(j);
list.set(j, list.get(j+1));
list.set(j+1, use);
}
}
}
for (User user : list) {
System.out.println(user.getName()+"==="+user.getAge());
}
}
}
class User{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}