package com.imooc.collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class CollectionsTask {
public void collectionSort(){
List<String> stringList=new ArrayList<String>();
String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random=new Random();
for(int i=0;i<10;i++){
StringBuffer sb;
do{sb=new StringBuffer();
int length=random.nextInt(9)+1;
for (int j=0;j<length;j++){
int num=random.nextInt(62);
sb.append(str.charAt(num));
}}while(stringList.contains(sb));
System.out.println("将要添加字符串:'"+sb+"'");
stringList.add(sb.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);
}
}
public static void main(String[] args) {
CollectionsTask collectionsTask=new CollectionsTask();
collectionsTask.collectionSort();
}
}