如题suo shi
public void testsort3() { String a="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYIOPASDFGHJKLzxcvbnm"; Random rd=new Random(); List<String>stringList=new ArrayList<String>(); for(int i=0;i<10;i++) { StringBuilder sb=new StringBuilder(); for(int j=0;j<1+rd.nextInt(10);j++) { char cr=a.charAt((int)(rd.nextInt(62))); sb=sb.append(String.valueOf(cr)); } System.out.println("获得字符串:"+sb); stringList.add(sb.toString()); } System.out.println("-------排序前---------"); for (String string :stringList) { System.out.println("元素:"+string); } System.out.println("-------排序后---------"); Collections.sort(stringList); for (String string :stringList) { System.out.println("元素:"+string); } }
全部代码拷过来,这局部代码不好看