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

交作业~~

public void testSort3(){

    List<String> strList = new ArrayList<String>();
    String basicStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    Random random = new Random();


    for(int i =0;i < 10;i++){

        StringBuffer sbf = new StringBuffer();
        int length = random.nextInt(10) + 1;

        for(int j = 0;j < length;j++){

            int charID = random.nextInt(basicStr.length());
            sbf.append(basicStr.charAt(charID));
        }

        if(!strList.contains(sbf.toString())){
            System.out.println("添加字符串:" + sbf.toString());
            strList.add(sbf.toString());
        }

    }

    System.out.println("------排序后------");

    Collections.sort(strList);
    for(String str:strList){
        System.out.println("元素为:" + str);
    }

}


正在回答

1 回答

int length = random.nextInt(10) + 1;

请问这一行是什么意思呢

0 回复 有任何疑惑可以回复我~
#1

肥川

看了下似乎是决定随机生成的字符串的长度?
2019-08-10 回复 有任何疑惑可以回复我~

举报

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

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

进入课程
意见反馈 帮助中心 APP下载
官方微信