Apache CollectionUtils subtract and removeAll difference

Maven 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