如何使用Java8使用两个列表准备第三个列表

如何使用Java8使用两个列表准备第三个列表,java,collections,Java,Collections,我有两个不同的列表,使用它们,我准备使用流的第三个列表 Student.java public class Student { int id; String name; public Student(int id, String name) { super(); this.id = id; this.name = name; } public int getId() { return i

我有两个不同的列表,使用它们,我准备使用流的第三个列表

Student.java

public class Student {

    int id;
    String name;

    public Student(int id, String name) {
        super();
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
StudentLoc.java

public class StudentLoc {

    int id;
    String loc;

    public StudentLoc(int id, String loc) {
        super();
        this.id = id;
        this.loc = loc;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLoc() {
        return loc;
    }

    public void setLoc(String loc) {
        this.loc = loc;
    }

}
我有下面的三等舱

StudentDetLoc.java

public class StudentDetLoc {

    int id;
    String name;
        String Loc;

}
  • 我必须使用id属性比较Student list和StudentLoc list
  • 如果两个列表中都有id,那么我必须使用这两个列表准备StudentDetlock列表
  • 我的做法是:

  • 使用
    streams()
    map()
  • 使用从步骤1获得的集合筛选第二个列表
  • 使用
    forEach()
    作为步骤2的终止操作,并附加到最后的第三个列表(仅保留
    id
    name
    Loc

    你能分享一下示例代码吗