CollectionUtils::removeAll() Commons Collections 3.2.1
I must be going crazy, becuase it seems like this method is doing the inverse of what the docs state:
Removes the elements in remove from collection. That is, this method returns a collection containing all the elements in c that are not in remove.
This little JUnit test
@Test
public void testCommonsRemoveAll() throws Exception {
String str1 = "foo";
String str2 = "bar";
String str3 = "qux";
List<String> collection = Arrays.asList(str1, str2, str3);
System.out.println("collection: " + collection);
List<String> remove = Arrays.asList(str1);
System.out.println("remove: " + remove);
Collection result = CollectionUtils.removeAll(collection, remove);
System.out.println("result: " + result);
assertEquals(2, result.size());
}
Is failing with
java.lang.AssertionError: expected:<2> but was:<1>
and prints
collection: [foo, bar, qux]
remove: [foo]
result: [foo]
From my reading of the docs I should expect [bar, qux]
. What have I missed?