第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

記錄一下課程作業(yè)

public?class?CollectionsTest?{

????public?int?length;
????public?static?final?String?ALLCHAR?=?"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

????/**
?????*?1.通過(guò)Collections.sort()方法,對(duì)Integer泛型的List進(jìn)行排序;
?????*?創(chuàng)建一個(gè)Integer泛型的List,插入十個(gè)100以內(nèi)的不重復(fù)隨機(jī)整數(shù),
?????*?調(diào)用Collections.sort()方法對(duì)其進(jìn)行排序
?????*/
????public?void?testSort1(){
????????List<Integer>?integerList?=?new?ArrayList<Integer>();
????????//?插入十個(gè)100以內(nèi)的不重復(fù)隨機(jī)整數(shù)
????????Random?random?=?new?Random();
????????Integer?k;
????????for(int?i=0;i<10;i++){
????????????do{
????????????????k?=?random.nextInt(100);
????????????}while?(integerList.contains(k));
????????????integerList.add(k);
????????????System.out.println("成功添加整數(shù):"+k);
????????}
????????System.out.println("------------------序列排序前--------------------");
????????for(Integer?integer?:?integerList){
????????????System.out.println("元素:"+integer);
????????}
????????Collections.sort(integerList);
????????System.out.println("------------------序列排序后--------------------");
????????for(Integer?integer?:?integerList){
????????????System.out.println("元素:"+integer);
????????}
????}

????/**
?????*?2.對(duì)String泛型的List進(jìn)行排序;
?????*?創(chuàng)建String泛型的List,添加三個(gè)亂序的String元素,
?????*?調(diào)用sort方法,再次輸出排序后的順序
?????*/
????public?void?testSort2(){
????????List<String>?stringList?=?new?ArrayList<String>();

????????//?插入十個(gè)100以內(nèi)的不重復(fù)隨機(jī)整數(shù)
????????Random?random?=?new?Random();

????????for(int?i=0;i<10;i++){
????????????StringBuffer?buf?=?new?StringBuffer();
????????????length?=?random.nextInt(10)?+?1;
????????????do{
????????????????for(int?j=0;j<length;j++){
????????????????????int?number?=?random.nextInt(ALLCHAR.length());
????????????????????buf.append(ALLCHAR.charAt(number));
????????????????}
????????????}while(stringList.contains(buf.toString()));
????????????stringList.add(buf.toString());
????????????System.out.println("成功添加元素:"?+?buf);
????????}
????????System.out.println("-------排序前-------");
????????for?(String?str:stringList
?????????????)?{
????????????System.out.println("元素:"+str);
????????}
????????Collections.sort(stringList);
????????System.out.println("-------排序后-------");
????????for?(String?str:stringList
????????????????)?{
????????????System.out.println("元素:"+str);
????????}
????}

????/**
?????*?3.對(duì)其他類型泛型的List進(jìn)行排序,以Student為例。
?????*/
????public?void?testSort3(){
????????List<Student>?studentList?=?new?ArrayList<Student>();
????????List<String>?stringList?=?new?ArrayList<String>();
????????Random?random?=?new?Random();
????????String?strnum;
????????for(int?i=0;i<3;i++){
????????????int?number?=?random.nextInt(1000);
????????????do{
????????????????strnum?=?Integer.toString(number);
????????????}while?(stringList.contains(strnum));
????????????stringList.add(strnum);
????????}
????????
????????studentList.add(new?Student(stringList.get(0),"tom"));
????????studentList.add(new?Student(stringList.get(1),"jack"));
????????studentList.add(new?Student(stringList.get(2),"jerry"));

????????System.out.println("--------排序前--------");
????????for?(Student?stu:?studentList
?????????????)?{
????????????System.out.println("學(xué)生的姓名為:"+stu.getName()+",學(xué)生的ID為:"+stu.getId());
????????}
????????Collections.sort(studentList);
????????System.out.println("--------排序后--------");
????????for?(Student?stu:?studentList
????????????????)?{
????????????System.out.println("學(xué)生的姓名為:"+stu.getName()+",學(xué)生的ID為:"+stu.getId());
????????}
????????System.out.println("--------使用comparator排序--------");
????????Collections.sort(studentList,new?StudentComparator());
????????for?(Student?stu:?studentList
????????????????)?{
????????????System.out.println("學(xué)生的姓名為:"+stu.getName()+",學(xué)生的ID為:"+stu.getId());
????????}
????}


????public?static?void?main(String[]?args)?{
????????CollectionsTest?ct?=?new?CollectionsTest();
????????//ct.testSort1();
????????//?ct.testSort2();
????????ct.testSort3();
????}
}


正在回答

1 回答

針對(duì)課后作業(yè)寫了一下testSort2()方法和testSort3()方法。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門第三季
  • 參與學(xué)習(xí)       409775    人
  • 解答問(wèn)題       4546    個(gè)

Java中你必須懂得常用技能,不容錯(cuò)過(guò)的精彩,快來(lái)加入吧

進(jìn)入課程

記錄一下課程作業(yè)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)