public void testSort3(){
List<Student> studentList = new ArrayList<Student>();
List<Integer> integerList = new ArrayList<Integer>();
Random random = new Random();
Integer id;
String[] names = {"Mike","Angela","Lucy"};
for(int i = 0; i < 3; i++ ){
do{
id = random.nextInt(1000);
}while(integerList.contains(id) || id.equals(0));
integerList.add(id);
studentList.add(new Student(id.toString(), names[i]));
}
System.out.println("----------排序前-----------");
for(Student student : studentList){
System.out.println("学生:" + student.id + ":" + student.name);
}
Collections.sort(studentList);
System.out.println("----------排序后-----------");
for(Student student : studentList){
System.out.println("学生:" + student.id + ":" + student.name);
}
}
打开App,阅读手记