交作业,又是参考问答里的,我好废啊
package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Testsort {
List<String> lt=new ArrayList<String>();
Random random=new Random();
String str="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789";
void dataAdd() {
for(int i=0;i<10;i++) {
StringBuilder st=new StringBuilder();
int s=random.nextInt(10);
for(int j=0;j<s+1;j++) {
int a=random.nextInt(62);
st.append(str.charAt(a));
}
if(lt.contains(st)) {
continue;
}
else {
lt.add(st.toString());
}
}
System.out.println("----------排序前-----------");
for(String show:lt) {
System.out.println(show);
}
Collections.sort(lt);
System.out.println("----------排序后-----------");
for(String show2:lt) {
System.out.println(show2);
}
}
public static void main(String[] args) {
new Testsort().dataAdd();
}
}