慕沐309667
2017-07-14 12:11:45浏览 1890
public void testSort3(){
List<String> stringList=new ArrayList<String>();
String c="0123456789qwertyuiopasdfghjklzxcvbmnQWERTYUIOPASDFGHKJLZXCVBNM";
Random random=new Random();
char[] sb=new char[10];
String sr;
for (int i = 0; i < 10; i++) {
do {
int k=random.nextInt(10);
for (int j = 0; j < k; j++) {
sb[j]=c.charAt(random.nextInt(c.length()));
}
sr=String.valueOf(sb);
} while (stringList.contains(sr));
stringList.add(sr);
}
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);
}
}