有没有毛病?
package com.class6;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public static void main(String[] args) {
// TODO Auto-generated method stub
CollectionsTest ct=new CollectionsTest();
ct.testSort3();
}
public void testSort3() {
List<String> stringList=new ArrayList<String>();
StringBuilder s=new StringBuilder("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
Random random=new Random();
int stringLength;
for(int i=0;i<10;i++) {
stringLength=(int) (Math.random()*10+1);
StringBuilder randomString=new StringBuilder(stringLength);
for(int j=0;j<stringLength;j++) {
int randomCharIndex=(int)(Math.random()*62);
char randomChar=s.charAt(randomCharIndex);
randomString.append(randomChar);
}
stringList.add(randomString.toString());
}
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);;
}
}