课后练习6-5
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class cheshiL {
public static List<String>string=new ArrayList<String>();
public static void csl(){
Random random=new Random();
String stringa="QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890";
for(int i=0;i<10;i++){
StringBuilder sb=new StringBuilder();
int k;
do{
k=random.nextInt(10);
for(int w=0;w<k;w++){
sb=sb.append(stringa.charAt(random.nextInt(62)));
}
}while(k==0 ||string.contains(sb));
string.add(sb.toString());
System.out.println("成功添加整数:"+sb.toString());
}
System.out.println("----------排序前---------");
for (String string2 : string) {
System.out.println("元素:"+string2);
}
Collections.sort(string);
System.out.println("----------排序后---------");
for (String string2 : string) {
System.out.println("元素:"+string2);
}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
cheshiL.csl();
}
}