过眼皆云烟
2016-03-13 17:58
public void testSort3() { List<String> stringList = new ArrayList<String>(); Random random = new Random(); String string = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; StringBuffer sBuffer = new StringBuffer(); for (int i = 0; i < 10; i++) { do { for (int j = 1; j <= random.nextInt(10); j++) { sBuffer = sBuffer.append(string.charAt(random.nextInt(62))); } } while (stringList.contains(sBuffer)||stringList.contains(null)); String s = sBuffer.toString(); stringList.add(s); System.out.println("成功添加字符串:" + s); sBuffer.delete(0, sBuffer.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 +"'"); }
for (int j = 1; j <= random.nextInt(10); j++) 如果随机到1的话 或者0 这个循环还走么?
Java入门第三季
409792 学习 · 4340 问题
相似问题
回答 2
回答 2