我有一个带有以下签名的类Model:
class Model {
private String stringA;
private String stringB;
public Model(String stringA,String stringB) {
this.stringA = stringA;
this.stringB = stringB;
}
public String getStringA() {
return stringA;
}
public String getStringB() {
return stringB;
}
}
我想映射List< Model>到列表< String>在单个流中包含stringA和stringB
List strings = models.stream()
.mapFirst(Model::getStringA)
.thenMap(Model::getStringB)
.collect(Collectors.toList());
要么:
List strings = models.stream()
.map(Mapping.and(Model::getStringA,Model::getStringB))
.collect(Collectors.toList());
当然,他们都没有编译,但你明白了.
它有可能吗?
编辑:
例:
Model ab = new Model("A","B");
Model cd = new Model("C","D");
List stringsFromModels = {"A","B","C","D"};