作业!!!
public void testSort2() {
List<String>sl=new ArrayList<String>();
Random random=new Random();
String st = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for(int i=0;i<10;i++) {
StringBuilder string1=new StringBuilder();
do {
int length=random.nextInt(10);
for(int j=0;j<((length==0)?1:length);j++){
int index = random.nextInt(st.length());
string1.append(st.charAt(index));
}
}while(sl.contains(string1));
sl.add(string1.toString());
}
System.out.println("-------排序前-------");
for (String string : sl) {
System.out.println("字符串元素:"+string);
}
System.out.println("-------排序后-------");
Collections.sort(sl);
for (String string : sl) {
System.out.println("字符串元素:"+string);
}
}