列出没有重复? [英] List without duplicates?

查看:131
本文介绍了列出没有重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚读了是否有无重复的列表实施关于列表,NOT 设置,不允许重复的实现。接受的答案建议使用Collections15 SetUniqueList 。是否有一些等价的 - 在番石斛? (我搜索的文档,不能找到) - 在其他库或有其他当前流行的解决方案?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆