public void testSort2(){
List<String> stringList=new ArrayList<String>();
Random r1=new Random();
Random r2=new Random();
String base="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int length=base.length();
for(int i=0;i<10;i++){
StringBuffer sb=new StringBuffer();
do{
for(int j=0;j<r1.nextInt(10);j++){
int num=r2.nextInt(length);
sb.append(base.charAt(num));
}
}while(stringList.contains(sb.toString()));
stringList.add(sb.toString());
}
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);
}
}
热门评论