public void sortRandomStringList(){
// 所有字符
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
// 创建String类的List
List<String> stringList = new ArrayList<String>();
// 随机生成10个长度为10以内的随机整数
Random random = new Random();
for(int i = 0;i<10;i++){
StringBuilder k = new StringBuilder("");
// 保证k不重复
do{
int count = random.nextInt(10);
for(int j=1;j<=count;j++){
char c = chars.charAt(random.nextInt(chars.length()-1));
k.append(c);
}
}while(stringList.contains(k.toString()));
stringList.add(k.toString());
System.out.println("成功添加字符串:"+k);
}
// stringList
System.out.println("排序前:");
System.out.println(stringList.toString());
// 排序
Collections.sort(stringList);
System.out.println("排序后:");
System.out.println(stringList.toString());
}