手记

collection.sort()作业

public void testsSort4(){
List<String> stringlist=new ArrayList<String>();
String str="abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random ran=new Random();

    for(int i=0;i<10;i++){
        int m=ran.nextInt(9)+1;
        char[] df=new char[m];
        for(int j=0;j<m;j++){               
            int number=ran.nextInt(62);
            df[j]=str.charAt(number);
            }
        String  n=String.valueOf(df);
        stringlist.add(n);
    }
    System.out.println("------排序前------");
    for(String sring:stringlist){
        System.out.println("元素:"+sring);
        }
    Collections.sort(stringlist);
    System.out.println("------排序后---------");
    for(String sring:stringlist){
        System.out.println("元素:"+sring);
        }
}
1人推荐
随时随地看视频
慕课网APP