英文:
The Filter of my Java- Stream does not work
问题
我无法解释为什么我的过滤器不起作用。我在if
语句中排除了条件,以检查条件是否真的为真,它确实为真。当DefaultLang
(v.getLinkDefaultLang()
)和currentLang
(v.getLinkCurrentLang()
)为Null时,我不想在我的List
中保留该值!
manualResponseTOs.values().stream()
.filter(v -> isEmpty(v.getLinkDefaultLang()) && isEmpty(v.getLinkCurrentLang()))
.collect(Collectors.toList());
英文:
I can´t explain why my filter does not work. I exclude the condition in an if
-statement to check that the condition is really true and it is. I don´t want to have the value in my List
when the DefaultLang
(v.getLinkDefaultLang()
) and the currentLang (v.getLinkCurrentLang()
) are Null!
manualResponseTOs.values().stream()
.filter(v -> isEmpty(v.getLinkDefaultLang()) && isEmpty(v.getLinkCurrentLang()))
.collect(Collectors.toList());
答案1
得分: 1
谢谢!现在我有了解决方案。
filter(v -> !(isEmpty(v.getLinkDefaultLang()) && isEmpty(v.getLinkCurrentLang())))
英文:
Thanks! Now I have the solution.
filter(v-> !(isEmpty(v.getLinkDefaultLang()) && isEmpty(v.getLinkCurrentLang())))
答案2
得分: 0
你还可以根据条件进行过滤,而不是将所有条件都放在同一行,如果你愿意的话。这样更容易阅读。
manualResponseTOs.values().stream()
.filter(v -> !isEmpty(v.getLinkDefaultLang()))
.filter(v -> !isEmpty(v.getLinkCurrentLang()))
.collect(Collectors.toList());
英文:
You can also filter per condition as opposed to having all conditions on the same line if you like. It's a bit more readable.
manualResponseTOs.values().stream()
.filter(v -> !isEmpty(v.getLinkDefaultLang()))
.filter(v -> !isEmpty(v.getLinkCurrentLang()))
.collect(Collectors.toList());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论