平生事
2017-07-06 11:48:34浏览 2321
List<String> stringList = new ArrayList<>();
String s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (int j = 0; j < 10; j++) {
Random random = new Random();
int y = random.nextInt(30) + 1;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < y; i++) {
Random index = new Random();
int x = index.nextInt(s.length());
sb.append(s.charAt(x));
}
stringList.add(new String(sb));
}
System.out.println("**********排序前**********");
for (String sl :
stringList) {
System.out.println("第" + stringList.indexOf(sl) + "个元素为:" + sl);
}
Collections.sort(stringList);
System.out.println("\r");
System.out.println("**********排序后**********");
for (String sl :
stringList) {
System.out.println("第" + stringList.indexOf(sl) + "个元素为:" + sl);
}