【发布时间】:2020-07-25 22:20:34
【问题描述】:
我有两个列表源和目标想要根据某些条件合并它们并将数据推送到 Hashmap。我尝试了下面的代码,但我无法成功。
public List<Persona> fetchCommonPersonas(List<User> sourceList,
List<User> targetList) {
final Map<String, String> map = new HashMap<>();
map = sourceList.stream()
.filter(source -> targetList.stream().anyMatch(destination -> {
if(destination.getAge().equals(source.getAge())) {
map.put(source.getUserId(), destination.getUserId());
}
}
));
}
【问题讨论】: