public class CollectionSort {
public void sort3(){
List<Student> studentList = new ArrayList<Student>();
List<Integer> i = new ArrayList<Integer>();
Random r = new Random();
int n;
for(int j=0;j<3;j++){
do{
n = r.nextInt(1000);
}while(i.contains(n));
i.add(n);
}
studentList.add(new Student(i.get(0).toString(),"小明"));
studentList.add(new Student(i.get(1).toString(),"小红"));
studentList.add(new Student(i.get(2).toString(),"小刚"));
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);
}
}
public static void main(String[] args) {
CollectionSort cs = new CollectionSort();
cs.sort3();
}
}
多多指教!