public void testSort6(){
List<Student> studentList=new ArrayList<Student>();
Random random=new Random();
Integer id1=random.nextInt(100);
Integer id2;
Integer id3;
do{
id2=random.nextInt(100);
}while(id1==id2);
do{
id3=random.nextInt(100);
}while(id3==id2||id1==id3);
Student st1=new Student(id1+"","Jack");
Student st2=new Student(id2+"","Lucy");
Student st3=new Student(id3+"","Silence");
studentList.add(st1);
studentList.add(st2);
studentList.add(st3);
System.out.println("--------排序前--------");
for (Student student : studentList) {
System.out.println("学生为"+student.id+" "+student.name);
}
Collections.sort(studentList);
System.out.println("--------排序后--------");
for (Student student2 : studentList) {
System.out.println("学生为"+student2.id+" "+student2.name);
}
//运行了好几次结果有时会出错,哪里有问题吗
//某次出错结果如下
--------排序前--------
学生为24 Jack
学生为18 Lucy
学生为4 Silence
--------排序后--------
学生为18 Lucy
学生为24 Jack
学生为4 Silence
...视频没看完就做的结果...
话说提问不可以撤销吗