我试图将数组中的索引设置为null,它一直有效,直到方法完成并恢复到之前的状态

时间:2015-04-20 00:25:10

标签: java

这是方法。它告诉我它在方法中将值设置为null,就像我已经检查过一样。但是在该方法完成之后,该值将恢复为之前将其设置为null的值。非常感谢帮助。

public void deleteStudent(String studentName) {
    //deletes a Student object by going through the array and checking for an student name the same as the entered name.
    boolean deleteCheck = false;
    for (int i = 0; i < studentList.length; i += 1) {
        if (studentList[i] != null) {
            Student a = this.studentList[i];
            if (a.getName().equals(studentName)) {
                studentList[i] = null;
                deleteCheck = true;
            }
        }
    }
    //deleteCheck is used to print a message if no student was deleted.
    if(!deleteCheck){
        System.out.println("There is no student on this course called " + studentName + ".");
    } else System.out.println("Student deleted.");
}

0 个答案:

没有答案