-
獲取List中課程的位置:
通過indexOf方法來取得某元素索引位置
if(courseToSelect.contains(course2)) System.out.println("課程:"?+?course2.name?+?"的索引位置為:"?+?courseToSelect.indexOf(coures2));
lastIndexOf(java):返回最后一個元素出現的索引位置
如果上述兩個方法都沒有實現,則返回-1。
查看全部 -
判斷set中課程是否存在:
查看全部 -
判斷List中課程是否存在
equals方法重寫:
public boolean equals(object obj){
? ?if(this == obj){
? ? ? ?return true;
? ? ? ?}
? ?if(obj == null)
? ? ? ?return false;
? ?if(!(obj instanceof Course))
? ? ? ?return false;
? ?Course course = (Course) obj;
? ?if(this.name==null){
? ? ? ?if(course.name==null)
? ? ? ? ? ?return true;
? ? ? ?else
? ? ? ? ? ?return false;
? ? ? ?}else{
? ? ? ?if(this.name.equals(course.name))
? ? ? ? ? ?return true;
? ? ? ?else
? ? ? ? ? ?return false
? ? ? ?}
}查看全部 -
修改Map中的信息
查看全部 -
刪除Map中的學生
查看全部 -
學生選課--使用Map添加學生
查看全部 -
map&HashMap類
查看全部 -
子類在前,父類在后
查看全部 -
foreach循環用法:
for(數據類型?元素變量:遍歷對象){ ?????}
隨機數產生:
int?x?=?(int)(Math.random()???*20); //產生20以內的隨機數
查看全部
舉報