我有两个不同的列表,并使用那些我准备使用流的第三个列表。
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;
}
}
student lo次.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;
}
}
我有下面的第三堂课。
student D ETL OC.Java
public class StudentDetLoc {
int id;
String name;
String Loc;
}
我的方法是:
streams()
和map()
从第一个列表中创建一组学生IDfilter()
第二个列表forEach()
作为步骤2的终止操作并附加到最终的第3个列表(仅保留id
,name
和Loc
)。