标签:
public void testSort3(){ List<String> str=new ArrayList<String>(); String st="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; do{ Random random=new Random(); StringBuilder sb=new StringBuilder(); Random random2=new Random(); int len=random2.nextInt(10);//获取字符串的随机长度len(10以内) if(len!=0){ for(int i=0;i<len;i++){ int num=random.nextInt(62);//获取随机字符 sb.append(st.charAt(num));//将字符追加到sb末尾 } } if((!str.contains(sb.toString())) && (sb!=null)&&(sb.toString().trim().length()!=0)){ str.add(sb.toString()); } }while(str.size()<10); System.out.println("-----------排序前----------"); for(String ss:str){ System.out.println("元素:"+ss); } Collections.sort(str); System.out.println("-----------排序后--------"); for(String sg:str){ System.out.println("元素:"+sg); } }
标签:
原文地址:http://www.cnblogs.com/miaoying/p/5617723.html