package com.imooc6;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class CollectionsTesta {
/**
* 1.创建完List<String>之后,往其中添加十条随机字符串
* 2,每条字符串的长度为10以内的随机数
* 3.每条字符串的每个字符都为随机生产的字符,字符可以重复
* 4.每条随机字符串不可重复
*/
public void testString(){
List<String> listString=new ArrayList<String>();
Random random=new Random();
Random random1=new Random();
String strs="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
StringBuilder str;
int b;
int a;
for(int j=0;j<10;j++){
str=new StringBuilder();
b=random.nextInt(10)+1;
for(int i=0;i<b;i++){
a=random1.nextInt(62);
str.append(strs.charAt(a));
}
listString.add(str.toString());
}
System.out.println("-------排序前-------");
for (String string : listString) {
System.out.println("元素:"+string);
}
Collections.sort(listString);
System.out.println("-------排序后-------");
for (String string : listString) {
System.out.println("元素:"+string);
}
}
/**
* @param args
*/
public static void main(String[] args) { // TODO Auto-generated method stub
CollectionsTesta ct=new CollectionsTesta();
ct.testString();
}
}