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

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

請(qǐng)大哥幫忙瞅瞅,為什么輸出亂碼呀

package?com.imooc.collection;

import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.List;
import?java.util.Random;

/**
?*?將要完成:
?*?1.通過(guò)Collections.sort()方法,對(duì)Integer泛型的List進(jìn)行排序;
?*?2.對(duì)String泛型的List進(jìn)行排序;
?*?3.對(duì)其他類型泛型的List進(jìn)行排序,以Student為例。
?*/

public?class?CollectionsTest?{

????/**
?????*?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?>();
????????stringList.add("microsoft");
????????stringList.add("google");
????????stringList.add("lenovo");
????????System.out.println("--------排序前--------");
????????for?(String?string:stringList){
????????????System.out.println("元素:"+string);
????????}
????????Collections.sort(stringList);
????????System.out.println("--------排序后--------");
????????for?(String?string:stringList){
????????????System.out.println("元素:"+string);
????????}
????}

????public?void?testSort3(){
????????List<Student>?studentList?=?new?ArrayList<Student>();
????????Random?random?=?new?Random();
????????studentList.add(new?Student(random.nextInt(1000)+"",",Mike"));
????????studentList.add(new?Student(random.nextInt(1000)+"","Angela"));
????????studentList.add(new?Student(random.nextInt(1000)+"","Lucy"));
????????System.out.println("--------排序前-------");
????????for?(Student?student:studentList){
????????????System.out.println("學(xué)生:"+student.id+":"+student);
????????}
????????Collections.sort(studentList);
????????System.out.println("--------排序后-------");
????}

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

}

http://img1.sycdn.imooc.com//607efdaf0001712717870291.jpg

正在回答

2 回答

這個(gè)輸出的是對(duì)象,你可以在student中重寫toString方法。

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

你輸出的是對(duì)象?System.out.println("學(xué)生:"+student.id+":"+student);

改成System.out.println("學(xué)生:"+student.id+":"+student.name);

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

舉報(bào)

0/150
提交
取消

請(qǐng)大哥幫忙瞅瞅,為什么輸出亂碼呀

我要回答 關(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)