随机生成不重复的字符串
//生成字符表
public void generatorAlphabeta(List<Character> list,char st,char ed){
for(char c= st;c<=ed;c++){
list.add(c);
}
}
public void testSort2(){
List<String> stringList = new ArrayList<String>();
List<Character> subList = new ArrayList<Character>();
generatorAlphabeta(subList, 'a', 'z');//将a-z加入字符表
generatorAlphabeta(subList, 'A', 'Z');//将A-Z加入字符表
generatorAlphabeta(subList, '0', '9');//将0-9加入字符表
//随机生成字符串
String str = "";
Random random = new Random();
for (int j = 0; j < 10; j++) {
str = "";
while(true){
for (int i = 0; i < random.nextInt(10); i++) {
double randomNum = 0.0;
int index = 0;
index = random.nextInt(62);
str = str + subList.get(index);
}//生成小于10长度的字符串
if(!str.equals("") && !stringList.contains(str)) break;//不为空且不重复就跳出字符串生成
}
stringList.add(str);//10条字符串
}
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);
}
}