随机字符串
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class aa {
public String sourse="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0123456789";
public void testSort2(){
List<String> stringList = new ArrayList<String>();
Random random = new Random();
for(int i=0;i<10;i++){
String str="";
do{
str= "";
int a=random.nextInt(9)+1;
for(int j=0;j<a;j++){
char cr=sourse.charAt(random.nextInt(sourse.length()-1));
str+=cr;}
}while (stringList.contains(str));
stringList.add(str);
System.out.println("成功添加字符串:"+str);}
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) {
// TODO 自动生成的方法存根
aa c= new aa();
c.testSort2();
}
}