慕粉3359002
2017-05-20 11:54:18浏览 2151
public void testSort02_LevelUp(){
List<String> stringList = new ArrayList<String>();
String c = "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
Random random = new Random();
String s;
char temp;
Integer k;
for(int i = 0;i<10;i++){
k = random.nextInt(10);
char[] cr = new char[k];
do{
for(int j = 0;j<k;j++){
temp =c.charAt(random.nextInt(c.length()));
cr[j] = temp;
}
s = String.valueOf(cr);
}while(stringList.contains(s));
stringList.add(s);
}
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);
}
}