package com.imooc.sortwork;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Sort {
public List<String> randomString;
public List<Character> elementsKit;
public Random random;
Sort(){
randomString=new ArrayList<String>();
elementsKit=new ArrayList<>();
random=new Random();
}
public void prepareRandomSring(){
//将a~z添加进Kit中
for(char i=97;i<=122;i++){
elementsKit.add(i);
}
//将A~Z添加进Kit中
for(char i=65;i<=90;i++){
elementsKit.add(i);
}
//将0~9添加进Kit中
for(char i=48;i<=57;i++){
elementsKit.add(i);
}
}//这是Kit中应该有62个elements了,最后一个的下标是61.
public void getRandomString(){
int i=0;
while(i<10){
StringBuilder[] string=new StringBuilder[10];
string[i]=new StringBuilder();
do{
for(int j=0;j<random.nextInt(10)+1;j++){
string[i].append(elementsKit.get(random.nextInt(62)).charValue());
}
}while(randomString.contains(string[i]));
randomString.add(string[i].toString());
i++;
}
}
public void show(){
for (Character ele : elementsKit) {
System.out.print(ele+" ");
}
}
public void sotr1(){
System.out.println("--------排序前的顺序----------");
for (String str : randomString) {
System.out.println("这是第"+(randomString.indexOf(str)+1)+"个字符串: "+str);
}
System.out.println();
System.out.println("--------排序后的顺序----------");
Collections.sort(randomString);
for (String str : randomString) {
System.out.println("这是第"+(randomString.indexOf(str)+1)+"个字符串: "+str);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Sort demo=new Sort();
demo.prepareRandomSring();
demo.getRandomString();
demo.sotr1();
}
}