手记

随机字符串排序(要十个字)

List<String> integerList = new ArrayList<String>();
        Random random = new Random();
        String s = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        for(int i = 0 ; i < 10 ; i++) {
            String s2 =new String();
            Integer a = random.nextInt(9)+1;
            do {
                for(int j = 0 ; j < a ; j++) {
                    s2 += String.valueOf(s.charAt(random.nextInt(s.length())));
                }
            }while(integerList.contains(s2));
            integerList.add(s2);
            System.out.println("添加了:"+s2);
        }

        System.out.println("=======排序前=======");
        for (String string : integerList) {
            System.out.println(string);
        }

        Collections.sort(integerList);

        System.out.println("-------排序后-------");
        for (String string : integerList) {
            System.out.println(string);
3人推荐
随时随地看视频
慕课网APP