public?void?testSort3()?{
??List<Student>?studentList?=?new?ArrayList<Student>();
??Student[]?stu?=?{new?Student("","Mike"),new?Student("","Angela"),new?Student("","Lucy")};
??Random?random?=?new?Random();
??Integer?k;
??for?(int?i?=?0;i?<?3;?i++){
???do?{
????k?=?random.nextInt(1000);
???}while?(studentList.contains(k));
??????String?st?=?String.valueOf(k);
??????stu[i].id?=?st;
??????System.out.println("成功添加學生:"??+?stu[i].id?+":"?+?stu[i].name);
??}
??studentList.addAll(Arrays.asList(stu));
??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);
??}
?}
2016-03-29
請加上 import java.util.Arrays;