输入代码public void testSort(){
List<String>sL=new ArrayList<String>();
String str="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random=new Random();
for(int i=0;i<10;i++){
StringBuffer st=new StringBuffer();
Integer lg;
do{
lg=random.nextInt(9)+1;//随机生成字符串长度
for(int j=0;j<lg;j++){
st.append(str.charAt(random.nextInt(62)));//从str中随机取出单个字符加入st中
}
}while(sL.contains(st));//无重复字符串
sL.add(st.toString());
System.out.println("将要添加的字符串:"+st);
}
System.out.println("----------排序前----------");
for(String string:sL){
System.out.println("元素:"+string);
}
Collections.sort(sL);
System.out.println("----------排序后-----------");
for(String string:sL){
System.out.println("元素:"+string);
}
}
public static void main(String[] args) {
CollectionsTest ct=new CollectionsTest();
ct.testSort();
}
點擊查看更多內容
15人點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦