已經(jīng)被移除的ID(鍵),還能調(diào)用其對(duì)應(yīng)的Value值嗎?
public void testRemove() {
// 獲取從鍵盤輸入的待刪除學(xué)生ID字符串
Scanner console = new Scanner(System.in);
while (true) {
// 提示輸入待刪除的學(xué)生的ID
System.out.println("請(qǐng)輸入要?jiǎng)h除的學(xué)生ID!");
String ID = console.next();
// 判斷該ID是否有對(duì)應(yīng)的學(xué)生對(duì)象
Student st = students.get(ID);
if (st == null) {
// 提示輸入的ID并不存在
System.out.println("該ID不存在!");
continue;
}
students.remove(ID);
System.out.println("成功刪除學(xué)生:" + st.name);
break;
}
}
這一段代碼中,
students.remove(ID);
System.out.println("成功刪除學(xué)生:" + st.name);
先執(zhí)行的remove(ID),再調(diào)用已經(jīng)被刪除的ID對(duì)應(yīng)的name嗎?都已經(jīng)刪除了,不存在,怎么還能調(diào)用被刪除的學(xué)生name?。?/p>
2015-12-30
刪除只是在students這個(gè)map里刪除了,st還在