keenone
2015-08-12 21:19
package collection_set_demo; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; public class CollectionsTest { public void testSort2(){ List<String> stringList = new ArrayList<String>(); Random random = new Random(); String source = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; for(int i = 0; i < 10; i++){ String string = ""; do{ int length = random.nextInt(11); for(int j = 0; j < length; j++){ char x = source.charAt(random.nextInt(source.length())); string = string + x; } }while(stringList.contains(string)); stringList.add(string); System.out.println("成功添加字符串:" + string + "\t\t" + ",字符串长度:" + string.length()); } System.out.println("----------------排序前---------------"); for (String string1 : stringList) { System.out.println(string1); } Collections.sort(stringList); System.out.println("----------------排序后---------------"); for (String string1 : stringList) { System.out.println(string1); } } public static void main(String[] args) { // TODO Auto-generated method stub CollectionsTest ct = new CollectionsTest(); ct.testSort2(); } }
写的很好
可以可以
Java入门第三季
409792 学习 · 4340 问题
相似问题