package collection1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Randomsort {
/**
* @param args
*/
static List<String>stringList=new ArrayList<String>();
public void test1(){
Random random=new Random();
for(int i=0;i<10;i++){
test2(random.nextInt(10)+1);
}
}
public void test2(int length){
Random random=new Random();
String sb="abcdefghijkrmnopqrstuvwxyzABCDEFGHIJKRMNOPQRSTUVWXYZ0123456789";
StringBuilder randomString=new StringBuilder();
for(int i=0;i<length;i++){
randomString.append(sb.charAt(random.nextInt(62)));
}
stringList.add(randomString.toString());
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Randomsort rs=new Randomsort();
rs.test1();
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);
}
}
}
热门评论
感觉写的不好,尤其那个不能确定随机字符串中是否有相同的!!求高手讲解!!