java lambada 实现多层嵌套的collector?
我有一个类
@Datapublic class AlterationImportQueryDto {
private List<Shape> shapeList;
@Data
public static class Shape {
private List<Flask> flaskList;
}
@Data
public static class Flask {
private Integer id;
}
}
此时我想要获得所有id的Set,用lambada应该怎么写
回答:
Set<Integer> ids = alterationImportQueryDto.getShapeList().stream() .flatMap(shape -> shape.getFlaskList().stream())
.map(Flask::getId).collect(Collectors.toSet());
回答:
flatMap
以上是 java lambada 实现多层嵌套的collector? 的全部内容, 来源链接: utcz.com/p/944640.html