手记

慕课网第三季课后练习

package Collection;

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

public class St {

public static void main(String[] args) {

    List<String> list = new ArrayList<String>();
    Random random = new Random();
    int x;
    String s = "0123456789qwertyuiopasdfghjklzxcvbnm";
    StringBuilder ss;
    String sss = "";
    for(int i=0;i<10;i++){
        ss = new StringBuilder();
        for(int j=0;j<random.nextInt(10)+1;j++){
            x=random.nextInt(s.length());
            ss.append(s.charAt(x));
        }
        do{
        sss=""+ss;
        list.add(sss);
        System.out.println("已添加元素:"+sss);
        }while(!list.contains(sss));
    }

    System.out.println("------排序前--------");
    for (String string : list) {
        System.out.println("元素:"+string);
    }
    System.out.println("--------排序后------");
    Collections.sort(list);
    for (String string : list) {
        System.out.println("元素:"+string);
    }
    }

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