以下代码是有关学生的基本信息。所以我的问题是如何从学生的姓氏中删除他(我想删除整个对象)?
public class Student{
private String firstName;
private String lastName;
private int numberOfIndexCard;
// constructors
public Student(){}
public Student(String firstName, String lastName, int numberOfIndexCard){
this.firstName = firstName;
this.lastName = lastName;
this.numberOfIndexCard = numberOfIndexCard;
}
public static void main(String [] args){
ArrayList<Student> students = new ArrayList<Student>("Thomas", "Anderson", 123);
ArrayList<Student> students = new ArrayList<Student>("James", "Butler", 456);
ArrayList<Student> students = new ArrayList<Student>("Harry", "Dawson", 789);
}
}
您可以使用removeIf
students.removeIf(stu->stu.getLastName().equals("lastname"));