黄VS金
2016-03-29 21:40
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); } }
请加上 import java.util.Arrays;
Java入门第三季
409792 学习 · 4340 问题
相似问题