// 随机添加String.
public void Test3() {
List<String> stringlist = new ArrayList<String>();
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
Random random2 = new Random();
for (int i = 0; i < 5; i++) {
StringBuffer sb = new StringBuffer();
int length;
do {
length = random2.nextInt(5);
} while (length==0);
for (int j = 0; j < length; j++) {
int number = random.nextInt(62);
sb = sb.append(str.charAt(number));
}
if (!stringlist.contains(sb)) {
String print = sb.toString();
System.out.println("添加了:" + print);
stringlist.add(print);
}
}
System.out.println(stringlist);
System.out.println("-----排序后:-----");
java.util.Collections.sort(stringlist);
for (String string : stringlist) {
System.out.println(string);
}
}