package com.imooc_collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class TestRandom {
List<String> StringList = new ArrayList<String>();
Random random = new Random();
public void TestAdd() {
for (int i = 0; i < 10;) {
int length = random.nextInt(10);
StringBuilder str = new StringBuilder("");
for (int j = 0; j < length;) {
int temp = random.nextInt(123);
if ((temp >= 48) && (temp <= 57)) {
char ch = (char) temp;
str.append(ch);
j++;
} else if ((temp >= 65) && (temp <= 90)) {
char ch = (char) temp;
str.append(ch);
j++;
} else if (temp >= 97) {
char ch = (char) temp;
str.append(ch);
j++;
} else {
continue;
}
}
if (StringList.contains(str.toString())) {
continue;
} else {
StringList.add(str.toString());
i++;
}
}
}
public void TestForEach() {
for (String string : StringList) {
System.out.println(string);
}
}
public void TestSort() {
System.out.println("--------排序前--------");
TestForEach();
System.out.println("--------排序后--------");
Collections.sort(StringList);
TestForEach(); }
public static void main(String[] args) {
// TODO Auto-generated method stub
TestRandom tr = new TestRandom();
tr.TestAdd();
tr.TestSort();
}
}