DEV Community 👩‍💻👨‍💻

Aldora
Aldora

Posted on

Apache CollectionUtils subtract and removeAll difference

Maven Dependency

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.1</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Difference between subtract and removeAll

You can use CollectionUtils.removeAll(collection, remove) or CollectionUtils.subtract(collection, remove) to remove certain element from collections, the difference is that the former can reuse element in remove variable, the later can not.
You can view detailed example here

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.