CollectionUtils::removeAll() Commons Collections 3.2.1
我一定要疯了,因为这种方法似乎与文档状态相反:
从集合中移除 remove 中的元素。也就是说,此方法返回一个集合,其中包含 c 中所有不在 remove 中的元素。
这个小小的 JUnit 测试
@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());
}
失败了
java.lang.AssertionError: 预期:<2> 但是是:<1>
并打印
collection: [foo, bar, qux]
remove: [foo]
result: [foo]
根据我对文档的阅读,我应该期待[bar, qux]
。我错过了什么?