package com.imooc.collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* Created by Songpan on 2016/8/21.
*/
public class RandomString {
public static String getRandowString(int length){
String base = "abcdefghigklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < length; i++) {
int number = random.nextInt(base.length());
stringBuffer.append(base.charAt(number));
}
return stringBuffer.toString();
}
public static void main(String[] args) {
List<String> sortRandomString = new ArrayList<String>();
Random random = new Random();
int length;
for (int i = 0; i < 10; i++) {
length = random.nextInt(10)+1;
sortRandomString.add(getRandowString(length));
}
Collections.sort(sortRandomString);
for (String s : sortRandomString) {
System.out.println(s);
}
}
}