課程
/后端開發(fā)
/Java
/Java入門第三季
遍歷學(xué)生對象stu課程時為啥會報錯呀?
2018-10-24
源自:Java入門第三季 4-11
正在回答
private?Set<Courses>?courses; public?Set<Courses>?getCourses()?{ return?courses; } public?void?setCourses(Set<Courses>?courses)?{ this.courses?=?courses; } //利用foreach遍歷student中選擇的課程 public?void?travelStudent(Students?student)?{ for(Courses?course:student.getCourses())?{ System.out.println("course:"+course.getId()+"?,?"+course.getName()); } }
構(gòu)造Student類的時候,需要進行泛型
private?Set<Courses>?courses; public?Set<Courses>?getCourses()?{ return?courses; } public?void?setCourses(Set<Courses>?courses)?{ this.courses?=?courses; } //利用foreach遍歷student中選擇的課程 public?void?travelStudent(Students?student)?{ for(Courses?course:student.getCourses())?{ System.out.println("course:"+course.getId()+"?,?"+course.getName()); } } //用于創(chuàng)建新的學(xué)生 public?Students(String?id,String?name)?{ this.id?=?id; this.name?=?name; this.courses?=?new?HashSet();//位于util.HashSet類中,是Set接口下的一個重要類 ?????????????????????????????//對courses進行實例化 }
沒泛型
沒有導(dǎo)包
慕雪1536570 提問者
舉報
Java中你必須懂得常用技能,不容錯過的精彩,快來加入吧
1 回答map如何遍歷
4 回答如何判斷S已經(jīng)完成遍歷
1 回答為啥報錯呀
2 回答關(guān)于遍歷ArrayList
3 回答關(guān)于forEach遍歷
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-11-22
private?Set<Courses>?courses; public?Set<Courses>?getCourses()?{ return?courses; } public?void?setCourses(Set<Courses>?courses)?{ this.courses?=?courses; } //利用foreach遍歷student中選擇的課程 public?void?travelStudent(Students?student)?{ for(Courses?course:student.getCourses())?{ System.out.println("course:"+course.getId()+"?,?"+course.getName()); } }2018-11-22
構(gòu)造Student類的時候,需要進行泛型
private?Set<Courses>?courses; public?Set<Courses>?getCourses()?{ return?courses; } public?void?setCourses(Set<Courses>?courses)?{ this.courses?=?courses; } //利用foreach遍歷student中選擇的課程 public?void?travelStudent(Students?student)?{ for(Courses?course:student.getCourses())?{ System.out.println("course:"+course.getId()+"?,?"+course.getName()); } } //用于創(chuàng)建新的學(xué)生 public?Students(String?id,String?name)?{ this.id?=?id; this.name?=?name; this.courses?=?new?HashSet();//位于util.HashSet類中,是Set接口下的一個重要類 ?????????????????????????????//對courses進行實例化 }2018-11-05
沒泛型
2018-10-24
沒有導(dǎo)包