public static void main(String[] args) {
List<String> list=new ArrayList<String>();
Random r=new Random();
StringBuffer s;
char c;
for(int i=0;i<10;i++){
do{
s=new StringBuffer();
int length=r.nextInt(10)+1;
for(int j=0;j<length;j++){
do{
c=(char)(r.nextInt('z'-'0'+1)+'0');
}while(!((c>='0'&&c<='9')||(c>='A'&&c<='Z')||(c>='a'&&c<='z')));
s.append(c);
}
}while(list.contains(s.toString()));
list.add(s.toString());
}
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);
}
}
打开App,阅读手记