为什么会生成空的字符串呢
public class CollectionTest2 {
public String basic = "abcdefghijklmnopqrstuvwxyzABCDEFDGHIJKLMNOPQRSTUVWXYZ1234567890";
public void testString(){
List<String> strings = new ArrayList<String>();
Random random = new Random();
for(int i=0;i<10;i++){
StringBuffer k = new StringBuffer();
do {
for(int j=0;j<random.nextInt(10);j++){
int num = random.nextInt(62);
k.append(basic.charAt(num));
}
} while (strings.contains(k.toString()));
strings.add(k.toString());
}
System.out.println("-------排序前--------");
for (String string : strings) {
System.out.println("元素"+string);
}
Collections.sort(strings);
System.out.println("-------排序后--------");
for (String string : strings) {
System.out.println("元素"+string);
}
}
public static void main(String[] args){
CollectionTest2 ct2 = new CollectionTest2();
ct2.testString();
}
}