package en.cc.course;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class CollectionSort {
public static List<StringBuffer>string = new ArrayList<StringBuffer>();——————————实例化一个List对象
public StringBuffer randomChar(){
StringBuffer along = new StringBuffer("ASDFGHJKLQWERTYuiopzxcvbnm1234567890");
StringBuffer buffer = new StringBuffer();
Random random = new Random();
for(int i=0;i<random.nextInt(10)+1;i++){
int s=random.nextInt(along.length());
char d=along.charAt(s);
buffer.append(d);
}
return buffer;
//System.out.println(buffer);
}
/*
* 生成10个随机字符串
*/
public void foreach(){
for (int i = 0; i < 10; i++) {
StringBuffer randomString = randomChar();
string.add(randomString);
}
}
/*
* 输出未排序前的10个字符串
*/
public void foreach2(){
for (StringBuffer stringBuffer : string) {
System.out.println(stringBuffer);
}
}
public void testSort(){
}
public static void main(String args[]){
CollectionSort ct = new CollectionSort();
ct.foreach();
ct.foreach2();
//Collections.sort(string); ——————————老师为什么不能这样用啊;,
}
}
D许咚
相关分类