6.5课后练习程序求指导 数组越界?
package sss;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class collectionstest {
public void sorttext3(){
List<String> a = new ArrayList<String>();
//String[] b = new String[10];
String st = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789";
Random c = new Random(10);
int i=0;
StringBuffer sb = new StringBuffer();
for(int z=0;z<10;z++){
do{
int j=c.nextInt();
for(;i<j;i++){
Random d = new Random(62);
int num = d.nextInt();
sb.append(st.charAt(num));
}
}while(a.contains(sb.toString()));
a.add(sb.toString());
}
System.out.println("···········排序前");
for (String string : a) {
System.out.println("元素"+a);
}
Collections.sort(a);
System.out.println("``````````排序后");
for (String string : a) {
System.out.println("元素 "+a);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
collectionstest a = new collectionstest();
// a.testsort1();
// a.sortText2();
a.sorttext3();
}
}