列出没有重复? [英] List without duplicates?
问题描述
I just read Is there a no-duplicate List implementation out there? answer about a List
, NOT Set
, implementation that doesn't allow duplicates. The accepted answer recommended the Collections15 SetUniqueList
. Is there some equivalent -- in Guava perhaps? (I searched the docs and couldn't find) -- in other libs or is there some other currently popular solution?
推荐答案
在你链接的答案的东西似乎相当充分。我会去那些解决方案之一。或者,您可以简单地扩展类 ArrayList
,并覆盖在调用之前对 HashSet
执行检查的一些方法 super.method
。只需添加Set作为一个实例字段,使用它检查重复和添加/删除添加到/从列表中删除的任何项。
The stuff in the answer you linked seems quite adequate. I'd go with one of those solutions. Alternatively, you could simply extend class ArrayList
and override some of the methods that do a check against a HashSet
prior to calling super.method
for that same method. Simply add the Set as an instance field, use it for checking dupes and add/remove whatever items get added to/removed from the list.
这篇关于列出没有重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!