找了半天代码一样,但是当删除学生ID的时候抛出异常
public void testRemove() { //获取从键盘输入的待删除学生的ID字符串 Scanner console = new Scanner(System.in); while(true) { //提示输入待删除的学生的ID System.out.println("请输入要删除的学生的ID:"); String ID = console.next(); //判断该ID是否有对应的学生对象 Student st=students.get(ID); if(st==null) { //提示输入的ID并不存在 System.out.println("该ID不存在!"); continue; } students.remove(ID); System.out.println("成功删除学生:"+st.name); break; } }