代码在此,不好意思啊,出了点意外:
public class Demo{
public static void main(String[] args) {
Student[] stus = new Student[3];
stus[0] = new Student("李跛子");
stus[1] = new Student("王二麻子");
stus[2] = new Student("张拐子");
delete(stus);
System.out.println(Arrays.toString(stus));
}
private static void delete(Student[] stus) {
for (Student student : stus) {
if ("张拐子".equals(student.name)) {
student = null;
break;
}
}
}
}
class Student {
public String name;
public Student(String name) {
this.name = name;
}
public String toString() {
return name;
}
} |