我试图通过使用 CollectionUtils.collate 方法找到两个集合的联合。此方法来自包org.apache.commons.collections4
这是代码部分:
Collection<String> tokensUnion2 = CollectionUtils.collate(
Arrays.asList(new String[]{"my", "sentence", "test", "for", "testing"}),
Arrays.asList(new String[]{"my", "sentence", "test", "is", "this"}),
false);
结果集合如下:
[my, sentence, test, for, test, is, testing, this]
如您所见,生成的集合包含重复项,即使CollectionUtils.collat e 的第三个参数表明我不想要重复项。
另外,字符串重复句子被消除了,但测试仍然存在。
我可以通过简单地将生成的集合放入HashSet来解决这个问题,但我想知道我做错了什么。
谢谢你。