市民高女士的小女儿
2017-08-29 11:39:57浏览 1829
public void testSort3(){
List<String> stringList = new ArrayList<>();
Random random = new Random();
String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
int count = 0 ;
while(count < 10){
int i = random.nextInt(10);
String newString = "";
for(int k = 0; k < i ;k++){
char c = chars.charAt((int)(double)random.nextInt(62));
newString = newString + c;
}
if(stringList.contains(newString)){
continue;
}
stringList.add(newString);
count ++;
System.out.println("第" + count + "次添加字符串:" + newString);
}
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);
}
}