手记

第三季6-5课后练习题原创

package com.imooc.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class CollectionPractice {

public void Generate(){
    String a="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    List<String> listString=new ArrayList<String>();

    Integer num=a.length();
    for(int i=0;i<10;i++){
        Random random=new Random();
        String fl="";
        Integer k=random.nextInt(9)+1;
        for(int m=0;m!=k;m++){
            Integer n=random.nextInt(a.length());
            fl+=a.charAt(n);
        }
        listString.add(fl);
    }
    System.out.println("--------排序前--------");
    for (String string : listString) {
        System.out.println(string);
    }
    System.out.println("--------排序后--------");
    Collections.sort(listString);
    for (String string : listString) {

        System.out.println(string);
    }
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    CollectionPractice result=new CollectionPractice();
    result.Generate();
}

}

1人推荐
随时随地看视频
慕课网APP