thomas
thomas

Reputation: 1271

Java : remove from list elements that start with elements from other list

Is there a way to do something like :

words.removeIf(specialWords::contains);

But by replacing "contains" by "startWith"

Upvotes: 0

Views: 402

Answers (1)

TomStroemer
TomStroemer

Reputation: 1540

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.

Upvotes: 1

Related Questions