package stringsort;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class stringsort {
public void test(){
List<String> list=new ArrayList();
String str3;
for(int i=0;i<10;i++){
do{
str3=random(10);
}while(list.contains(str3));
list.add(random(10));
}
System.out.println("---------排序前-----------");
for (String string : list) {
System.out.println("元素:"+string);
}
Collections.sort(list);
System.out.println("---------排序后-----------");
for (String string : list) {
System.out.println("元素:"+string);
}
}
public String random(int length){
String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random=new Random();
StringBuffer str1=new StringBuffer();
for(int i=0;i<length;i++){
int num=random.nextInt(62);
str1.append(str.charAt(num));
}
return str1.toString();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
stringsort str2=new stringsort();
str2.test();
}
}
热门评论
good !!!!!!!!!!!!!
学习了,感谢分享。继续学习。。。。