public void test02(){
List <String>stringList=new ArrayList<String>();
Random random=new Random();
String a="1234abcd";
for(int i=0;i<10;i++){
StringBuffer b=new StringBuffer();
do{
for(int j=0;j<random.nextInt(a.length());j++)
{
b.append(a.charAt(random.nextInt(a.length())));
}
}while(stringList.contains(b));
stringList.add(b.toString());
System.out.println("添加了:"+b);
}
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);
}
}
添加了:
添加了:2c
添加了:dbcca
添加了:214
添加了:d4d4b
添加了:4a
添加了:43bb
添加了:12
添加了:dccd
添加了:1d1d34
****排序前****
2c
dbcca
214
d4d4b
4a
43bb
12
dccd
1d1d34
****排序后****
12
1d1d34
214
2c
43bb
4a
d4d4b
dbcca
dccd