英文:
Java : remove from list elements that start with elements from other list
问题
有没有一种类似这样的方法:
words.removeIf(specialWords::startsWith);
但是将“contains”替换为“startsWith”?
英文:
Is there a way to do something like :
words.removeIf(specialWords::contains);
But by replacing "contains" by "startWith"
答案1
得分: 1
这应该会从“words”中删除以任何“specialWords”中的任何单词开头的所有项。
英文:
I would try the following:
words.removeIf(value -> specialWords.stream().anyMatch(value::startsWith));
This should remove every item from words
that start with any of the specialWords
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论