package ssan;
import java.util.List;
import java.util.Random;
import java.util.ArrayList;
import java.util.Collections;
public class string {
public void testsort(){
List <String> stringList=new ArrayList<String>();
String str="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random=new Random();//创建对象获取随机数
for(int i=1;i<=10;i++){
StringBuffer sd=new StringBuffer();//创建stringbuffer方法调用它里面的append()方法追加字符 ;
do{
for(int j=0;j<=random.nextInt(10)+1;j++){
sd.append(str.charAt(random.nextInt(str.length())));
}
}while(stringList.contains(sd));
stringList.add(sd.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);
}
}
public static void main(String[] args) {
string s=new string();
s.testsort();
}
}