public void testSort3() {
List<String>stringList = new ArrayList<String>();
Random random = new Random();
String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(int i =0;i<=10;i++) {
StringBuilder newString = new StringBuilder();
do {
int j;
do {
j = random.nextInt(10);
}while(j==0);
for(int k=0;k<j;k++) {
int l = random.nextInt(61);
newString.append(str.charAt(l));
}
}while(stringList.contains(newString));
stringList.add(newString.toString());
}
System.out.println("--------排序前--------");
for(String string:stringList){
System.out.println("元素:"+string);
}
Collections.sort(stringList);
System.out.println("--------排序后--------");
for(String string:stringList){
System.out.println("元素:"+string);
}
}
打开App,阅读手记