-1
ArrayList<Room> roomlist = new ArrayList<Roomlist>();
ArrayList<Subscriber> subscriberlist = new ArrayList<subscriber>();
ArrayList<Course> courserslist = new ArrayList<coursers>();
ArrayList<PC> pclist = new ArrayList<PC>();
ArrayList<Lecturer>  lecturertlist= new ArrayList <Lecturer>() ; 

我如何检查 Cource 列表中的 Subscriber 元素是否存在,并将他从

课程列表(不删除他)

非常感谢

4

1 回答 1

0

如果您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 
    }
于 2013-08-14T09:11:58.840 回答