帮助我从用户那里扫描名称和年龄,而不是在ArrayList中预定义它。
我在以下程序中初始化了姓名和年龄,可以帮助我从用户那里扫描姓名和年龄,它应该进行比较,然后再使用collection进行排序。
public class Control {
public static void main(String[] args) {
List<Student> studs = new ArrayList<Student>();
Student stu1 = new Student(22, "Gokul");
Student stu2 = new Student(12, "Dolby");
Student stu3 = new Student(24, "Rahul");
Student stu4 = new Student(56, "Raj");
studs.add(stu1);
studs.add(stu2);
studs.add(stu3);
studs.add(stu4);
Collections.sort(studs,new StudAge());
for(Student stud : studs) {
System.out.println(stud);
}
}
}
相关分类