业务场景:xList为所有水果,list为现有水果种类及数量
举个例子:xList: {“苹果”,“菠萝”,“荔枝”,“西瓜”,“百香果”}
list: {"苹果,2",“西瓜,“5”}
resultList: {2,0,0,5,0}
private List<Integer> list(List<String> xList, List<StaticsBean> list) {
List<Integer> resultList = xList.stream().map(a -> list.stream()
.filter(m -> Objects.equals(a,m.getName()))
.findFirst().map(m -> {
m.getValue();
return m.getValue();
}).orElse(0))
.filter(Objects::nonNull).collect(Collectors.toList());
return resultList;
}