package imooc_exception_demo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class StringSort {
List<String> stringList= new ArrayList<String>();
public void testSort2(){
Random random = new Random();
for(int i=0;i<10;i++){
int j = random.nextInt(9)+1;
String s1="";
for(int k=0;k<j;k++){
int num=random.nextInt(62);
if(num>9)
s1=s1+(char)('A'+(num-9));//取0-9 A-Z a-z 中间有特殊字符不知道怎么处理
else
s1=s1+num;
}
System.out.println("成功添加字符串:"+s1);
stringList.add(s1);
}
System.out.println("--------排序前-----------");
for(String ss:stringList){
System.out.println("元素:"+ss);
}
Collections.sort(stringList);
System.out.println("--------排序后-----------");
for(String ss:stringList){
System.out.println("元素:"+ss);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
StringSort ss = new StringSort();
ss.testSort2();
}
}
打开App,阅读手记