如果您Subscriber
如下并假设您Course
与我在下面的课程有些相似。您可以尝试以下操作
public class Subscriber {
private List<Course> courses=new ArrayList<>();
public List<Course> getCourses() {
return courses;
}
public void setCourses(List<Course> courses) {
this.courses = courses;
}
}
.
public class Course {
private int courseId;
private String courseName;
public int getCourseId() {
return courseId;
}
public void setCourseId(int courseId) {
this.courseId = courseId;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
}
现在让我们删除一个元素。
List<Subscriber> subscribers=new ArrayList<>();
List<Course> courses=new ArrayList<>();
Subscriber subscriber=new Subscriber();
Course course=new Course();
course.setCourseId(1);
course.setCourseName("one");
courses.add(course);
subscriber.setCourses(courses);
subscribers.add(subscriber);
for (Subscriber i:subscribers){
i.getCourses().remove(0); // remove 0 index element
}