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

随机字符串排序程序!请多多指教!

public void sort3(){
  List<String> stringList=new ArrayList<String>();
  String s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  Random random=new Random();
  for(int i=0;i<10;i++){
     StringBuffer str=new StringBuffer(); 
  do{
    for(int j=0;j<random.nextInt(10);j++){
    int num=random.nextInt(s.length());
    str.append(s.charAt(num)); }
   }while(stringList.contains(str.toString()));
   
   stringList.add(str.toString());}
   
   
  System.out.println("------------排序前-----------------");
  for(String string:stringList){
   System.out.println("字符串为:"+string);
  }
  Collections.sort(stringList);
  System.out.println("------------排序后-----------------");
  for(String string:stringList){
   System.out.println("字符串为:"+string);
  }
   
   }

正在回答

1 回答

就是这样


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

慕粉3170877 提问者

非常感谢!
2016-07-09 回复 有任何疑惑可以回复我~

举报

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

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

进入课程

随机字符串排序程序!请多多指教!

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