/*1.创建完List<String>之后,往其中添加十条随机字符串
- 2.每条字符串的长度为10以内的随机整数
- 3.每条字符串的每个字符都为随机生成的字符,字符可以重复
- 4.每条随机字符串不可重复
-
*/
public void testsort3(){
List<String> stringList=new ArrayList<String>();
String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random=new Random();
StringBuffer sb= new StringBuffer();
int i=0,j=0,length;
for( i=0;i<10;){
length=random.nextInt(11);
if(sb!=null)
sb=new StringBuffer();
for( j=0;j<length;j++)
{
int number=random.nextInt(62);
sb.append(str.charAt(number));
}
if(!stringList.contains(sb.toString()))
{
System.out.println("将要添加的字符串:'"+sb.toString()+"'");
stringList.add(sb.toString());
i++;
}
}
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);
}
}