日常交作业
public void testSort3() {
List<String> stringList = new ArrayList<String>();
//随机字符串
String strs = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int strsLen = strs.length();
Random rd = new Random();
for(int i=1;i<=10;i++) {
String str = "";
do {
int strLen = rd.nextInt(10);
if(strLen == 0) strLen = rd.nextInt(10);
System.out.println(strLen);
for(int j=0;j<strLen;j++) {
int index = rd.nextInt(strsLen-1);
char s = strs.charAt(index);
str = str+s;
}
}while(stringList.contains(str));
System.out.println("第"+i+"个字符串:"+str);
stringList.add(str);
}
System.out.println("---------------------排序前------------------");
for(String string : stringList) {
System.out.println("元素:"+string);
}
System.out.println("---------------------排序后------------------");
Collections.sort(stringList);
for(String string : stringList) {
System.out.println("元素:"+string);
}
}