各位大神看一下有什么需要改進的
之前一直想不起來ascall表中對應關系,32到128之外的字符打出來都是亂碼,上網查了才知道32到128這個區間,折騰死我了
package imooc.select_courses_system2;
import java.util.*;
public class CollectionsTest {
public void addStringAndSort(){
List<String> stringList=new ArrayList<String>();//創建一個arraylist類型的對象
for(int i=0;i<10;i++){ //for循環產生10個隨機字符串
Random random=new Random();
int k=0;//定義一個k用于產生隨機字符串長度
while(true){
StringBuilder stb=new StringBuilder();
k=random.nextInt(10); ?
for(int j=0;j<k;j++){ ?
stb=stb.append((char)(32+random.nextInt(96)));//產生對應ascall表中32到128之間的任意字符
}
if(stringList.contains(stb.toString()))
continue;
else if(!(stringList.contains(stb.toString()))&&stb!=null){
stringList.add(stb.toString());
break;
}
}
}
System.out.println("---------排序前---------");
for(String str1:stringList){
System.out.println(str1);
}
System.out.println("-----------排序后-----------");
Collections.sort(stringList);
for(String str1:stringList){
System.out.println(str1);
}
}
public static void main(String[] args) {
// TODO 自動生成的方法存根
CollectionsTest ct=new CollectionsTest();
ct.addStringAndSort();
}
}
另外請哪位大神幫我看一下我上一個問題,實在不知道為什么
2016-07-01
你得問題是什么 要問什么呀?