我的排序100以上有效果,100以下没有效果了
//对其他类型泛型的List进行排序,以student为例
public void testSort3(){
List<Student> studentList = new ArrayList<Student>();
Random rd = new Random();
Integer suiji;
Integer suiji1;
Integer suiji2;
Integer suiji3;
Integer suiji4;
Integer suiji5;
do{
suiji = rd.nextInt(1000);
suiji1 = rd.nextInt(1000);
suiji2 = rd.nextInt(1000);
suiji3 = rd.nextInt(1000);
suiji4 = rd.nextInt(1000);
suiji5 = rd.nextInt(1000);
}while(studentList.contains(suiji));
studentList.add(new Student(suiji+"","小明"));
studentList.add(new Student(suiji1+"","小红"));
studentList.add(new Student(suiji2+"","小兰"));
studentList.add(new Student(suiji3+"","小黑"));
studentList.add(new Student(suiji4+"","小白"));
studentList.add(new Student(suiji5+"","小绿"));
System.out.println("------------排序前-------------");
for (Student student : studentList) {
System.out.println("排序前:" +student.id+"->"+ student.name);
}
System.out.println("------------排序后-------------");
Collections.sort(studentList);
for (Student student : studentList) {
System.out.println("排序后:" +student.id+"->"+ student.name);
}
}