Java:从列表中移除以另一个列表中的元素开头的元素。

huangapple go评论60阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月18日 21:05:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63469282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定