为了账号安全,请及时绑定邮箱和手机立即绑定

本节作业!

import java.sql.SQLOutput;
import java.util.*;

public class TestCollections {
 
    public static String getRandomString(Integer length){
        if(length==null || length <=0){
            return null;
        }
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for(int i=0; i<length; i++){
            //62个字符
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
       public void test4(){
        List<Student> studentList=new ArrayList<Student>();
        List<String> strings=new ArrayList<String>();
        Random random=new Random();
        String str;
           for (int i=0;i<3;i++)
           {
               do {
                   str=getRandomString(3);
               }while(strings.contains(str));
               strings.add(str);
           }
        studentList.add(new Student(strings.get(0),"make"));
        studentList.add(new Student(strings.get(1),"lucy"));
        studentList.add(new Student(strings.get(2),"jeke"));
           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) {
       TestCollections testCollections=new TestCollections();
      testCollections.test4();
     
    }

}


正在回答

举报

0/150
提交
取消
Java入门第三季
  • 参与学习       409780    人
  • 解答问题       4339    个

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

进入课程

本节作业!

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信