public void testCompar(){
List<Student> students = new ArrayList<>();
Random random = new Random();
List<String> ss = new ArrayList<>();//用来储存随机数
for(int i=0;i<3;i++) {
int num = random.nextInt(10);//产生十以内的随机数
String s = String.valueOf(num);//将随机数转化为字符串类型
if (!(ss.contains(s))) {
ss.add(s);
}
}
students.add(new Student( ss.get(0)+ "", "小明"));
students.add(new Student(ss.get(1) + "", "小红"));
students.add(new Student(ss.get(2) + "", "小兰"));
for (Student student:students) {
System.out.println("学生:"+student.no+":"+student.stuName);
}
Collections.sort(students);
System.out.println("**********************");
for (Student student:students) {
System.out.println("学生:"+student.no+":"+student.stuName);
}
}