首页 文章

Java Commons Collections removeAll

提问于
浏览
29

CollectionUtils::removeAll() Commons Collections 3.2.1

我一定是要疯了,因为看起来这个方法正在做与文档状态相反的方法:

从集合中删除remove中的元素 . 也就是说,此方法返回一个集合,其中包含c中未删除的所有元素 .

这个小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:expected:<2>但是:<1>

和打印

collection: [foo, bar, qux] 
remove: [foo] 
result: [foo]

从我对文档的阅读中我应该期待 [bar, qux] . 我错过了什么?

1 回答

相关问题