package com.imooc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
···
public class testSort {
public static void main(String[] args) {
// TODO Auto-generated method stub
List<String>stringList=new ArrayList<String>();
Random random=new Random();
String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuffer sb;
for(int i=0;i<10;i++)
{
sb=new StringBuffer();
int length=(int)(Math.random()*9)+1;
do{
for(int j=0;j<length;j++)
{
int number=random.nextInt(base.length());
sb.append(base.charAt(number));
}
}while(stringList.contains(sb));
stringList.add(sb.toString());
System.out.println("将要添加的字符串:" + sb.toString());
}
System.out.println("------排序前------");
for (String string : stringList)
{ System.out.println("元素:" + string); }
System.out.println("------排序后------");
Collections.sort(stringList);
for (String string : stringList)
{ System.out.println("元素:" + string); }
}
}
···