package com.v512;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class testSort {
public void test(){
List<String> listString=new ArrayList<String>();
String str ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random=new Random();
for(int j=0;j<10;j++){
StringBuffer sb = new StringBuffer();
int k=random.nextInt(9)+1;
do{
for(int i=0;i<k;i++){
int number = random.nextInt(str.length());
sb.append(str.charAt(number));
}
} while(listString.contains(sb)) ;
listString.add(sb.toString());
}
for(String string:listString){
System.out.println("字符串:"+string);
}
System.out.println("------------排序后-------------");
Collections.sort(listString);
for(String string2:listString){
System.out.println("字符串:"+string2);
}
}
public static void main(String[] args){
testSort ts=new testSort();
ts.test();
}
}
打开App,阅读手记