package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ConllectionsTest {
public static void StringListTest() {
List<String> stringList = new ArrayList<String>();
Random random = new Random();
StringBuffer buffer=new StringBuffer();
for(int i=0;i<10;i++) {
do {
int length=random.nextInt(10)+1;
while(length>0)
{
int randomint=random.nextInt(123);
if(randomint>=48&&randomint<=57||
randomint>=65&&randomint<=90||
randomint>=97&&randomint<=122)
{
char c=(char) randomint;
buffer.append(c);
}
else continue;
length--;
}
}while(stringList.contains(buffer.toString()));
stringList.add(buffer.toString());
buffer.setLength(0);
}
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) {
// TODO 自动生成的方法存根
StringListTest();
}
}