public void testPractice(){
List<String> stringList = new ArrayList<String>();
Random random = new Random();
StringBuffer sb=new StringBuffer();
String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Integer k;
do{
//循环10次生成10个随机字符串
for(int i=0;i < 10;i++){
//通过循环控制字符串的长度不大于10
k = random.nextInt(10);
for(int j=0;j < k;j++){
//随机生成字符
int number = random.nextInt(62);
sb.append(str.charAt(number));
}
stringList.add(sb.toString());
System.out.println("随机生成的字符串为:" + sb.toString());
sb.setLength(0);
}
}while(stringList.contains(stringList));
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);
}
}
打开App,阅读手记