package com.course;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ListSort {
List<String> stringList = new ArrayList<String>();
public final String allChar = "01234567abcdefghijklmnopqrstuvwxyzABCKEFGHIJKLMNOPQRSTUVWXYZ";
public final int NUM = 10;
public final int MAX = 10;
public String genOneString(){
StringBuffer sb = new StringBuffer();
int len;
Random ran = new Random();
len = ran.nextInt(10); //gernate the length of a string
while (len<1){ //string length shouldn't be 0
len = ran.nextInt(10);
}
for (int i=0;i<len;i++)
sb.append(allChar.charAt(ran.nextInt(allChar.length())));
return sb.toString();
}
public void genStringList(){
String s;
Random ran=new Random();
for (int i=0;i<NUM;i++){
s = genOneString();
while(stringList.contains(s)){
s = genOneString();
}
stringList.add(s);
}
}
public void sortList(){
Collections.sort(stringList);
}
public void displayStringList(){
for (String s:stringList){
System.out.println(s);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ListSort ls = new ListSort();
ls.genStringList();
System.out.println("********befor sorting********");
ls.displayStringList();
ls.sortList();
System.out.println("********after sorting********");
ls.displayStringList();
}
}