交作业喽。。。。。。。
package com.imooc.collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class CollectionsTest
{
public void testStringSort2()
{
List<String>stringList2=new ArrayList<String>();
String[] str1= {"a","b","c","d","e","f","g","h","i","g","k","m","n","o","p",
"q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7",
"8","9","0"};
String str=new String();//str存放生成的单个字符串
for(int i=0;i<10;i++)//外层循环决定生成十个随机的字符串
{
String str2=new String();//str2存放生成的随机字符串
int k;
k=1+(int)(Math.random()*(10+1-1));//生成随机字符串的长度k
for(int j=0;j<k;j++)//内层循环生成一个随机的字符串
{
int z; //在字符串数组str1中随机选择字符串str1[z]
z=(int)(Math.random()*35);
str=str1[z];
str2=str2+str;
}
stringList2.add(str2);//将str2传入stringList2中
}
System.out.println("------------排序前------------");
for (String string : stringList2)
{
System.out.println("字符串:"+string);
}
Collections.sort(stringList2);
System.out.println("-------------排序后-----------");
for (String string : stringList2)
{
System.out.println("字符串:"+string);
}
}
public static void main(String[] args)
{
CollectionsTest ct=new CollectionsTest();
ct.testStringSort2();
}
}