public void testSort3() {
List<String> stringList2 = new ArrayList<String>();
Random random = new Random();
char c ;
for (int i = 0; i < 10; i++) { //往其中添加十条随机字符串
String S = "";
int length = random.nextInt(10)+1;//字符串长度为十以内的随机整数
for(int j = 0; j < length;j++) {//往每条字符串中添加内容
int n = random.nextInt(62);
if(n<10) {
c = (char)(n+48);
}
else if(n<36) {
c = (char)(n+55);
}
else {
c = (char)(n+61);
}
S = S + c;
}
System.out.println("将要添加字符串:"+S);
stringList2.add(S);
}
System.out.println("--------排序前----------");
for (String string : stringList2) {
System.out.println("元素:"+string);
}
Collections.sort(stringList2);
System.out.println("--------排序后----------");
for (String string : stringList2) {
System.out.println("元素:"+string);
}
}