手记

参考大家的写的代码,用一个String对象把所有字母和数字装进去供选择easy

public void testSort3() {
    List<String>stringList = new ArrayList<String>();
    Random random = new Random();
    String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for(int i =0;i<=10;i++) {
        StringBuilder newString = new StringBuilder();
        do {
            int j;
            do {
                j = random.nextInt(10);
            }while(j==0);
            for(int k=0;k<j;k++) {
                int l = random.nextInt(61);
                newString.append(str.charAt(l));
            }
        }while(stringList.contains(newString));
        stringList.add(newString.toString());
    }
    System.out.println("--------排序前--------");
    for(String string:stringList){
        System.out.println("元素:"+string);
    }
    Collections.sort(stringList);
    System.out.println("--------排序后--------");
    for(String string:stringList){
        System.out.println("元素:"+string);
    }
}
0人推荐
随时随地看视频
慕课网APP