Apache CollectionUtils subtract and removeAll difference

Maven Dependency

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.1</version>
</dependency>

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. The following is an example:

From the above example, you can see that removeAll remove all duplicate elements, however, subtract only remove element in remove variable once