丿毛蛋
2018-08-24 14:38
String string = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; Random random = new Random(); ArrayList <String> list = new ArrayList<String>(); for (int i = 0;i<10;){ StringBuffer sb = new StringBuffer(); int length = random.nextInt(10); do{ sb.append(string.charAt(random.nextInt(62))); }while(sb.length()<length); if(!list.contains(sb)){ list.add(sb.toString()); i++; }else{ i=i; } } System.out.println("-------排序之前------"); for(String ss:list){ System.out.println(ss); } System.out.println("---------排序之后---------"); Collections.sort(list); for(String ss :list){ System.out.println(ss); }
你看着不别扭吗
666
66666666
Java入门第三季
409792 学习 · 4340 问题
相似问题