亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

作業作業作業

import java.util.List;

import java.util.Random;

import java.util.ArrayList;

import java.util.Collection;

import java.util.Collections;

public class CollectionsTest {public void testSort2(){

List<String> strings=new ArrayList<String>();

int length;

String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

StringBuffer sb=new StringBuffer();

Random random=new Random();

String str1;

for(int i=0;i<10;i++){

//循環避免重復

do{

sb.setLength(0);//字符串置空

length=random.nextInt(10);//產生10以內的字符串長度

//拼接字符串

for(int j = 0;j<length;j++){

int number=random.nextInt(62);

sb.append(str.charAt(number));

}

}while(strings.contains(sb.toString()) || sb.length()==0);//sb.length()==0避免產生一個空字符串

strings.add(sb.toString());

}

System.out.println("——————————————排序前————————————");

for (String string : strings) {

System.out.println("元素:"+string);

}

Collections.sort(strings);

System.out.println("——————————————排序后————————————");

for (String string : strings) {

System.out.println("元素:"+string);

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

CollectionsTest cTest=new CollectionsTest();

//cTest.testSort1();

cTest.testSort2();

}


}


正在回答

舉報

0/150
提交
取消
Java入門第三季
  • 參與學習       409767    人
  • 解答問題       4543    個

Java中你必須懂得常用技能,不容錯過的精彩,快來加入吧

進入課程

作業作業作業

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號