小白一枚,希望大家可以指出不足之处
public void testsort3(){
List<String> list = new ArrayList<String>();
Random random = new Random();
String k = null;
for(int i = 0;i < 10;i++){
String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuffer sb = new StringBuffer();
do{
for (int j = 0; j < random.nextInt(10); j++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
k = sb.toString();
}
}while(list.contains(k));
list.add(k);
System.out.println("添加字符串:"+k);
}
System.out.println("排序前:");
for (String string : list) {
System.out.println(string);
}
Collections.sort(list);
System.out.println("排序后:");
for (String string : list) {
System.out.println(string);
}
}