我要做的是过滤列表,然后映射它并使用orElseif null然后将其收集回列表.现在我可以通过这种方式实现它:
return users.stream()
.filter(user -> id.equals(user.getId()))
.map(
user -> {
if(user.getData() != null) {
return user.getData();
}
return Collections.emptyMap();
}
)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但问题是:我怎样才能使这个结构更好,为什么我不能orElse在这种情况下使用?