那里有没有重复的List实现? [英] Is there a no-duplicate List implementation out there?
问题描述
我知道 SortedSet
,但在我的情况下,我需要一些实现 List
而不是设置
。那么在API或其他地方有实施吗?
I know about SortedSet
, but in my case I need something that implements List
, and not Set
. So is there an implementation out there, in the API or elsewhere?
不应该很难实现自己,但我想到为什么不先在这里问人? / p>
It shouldn't be hard to implement myself, but I figured why not ask people here first?
推荐答案
标准库中没有Java集合来执行此操作。 LinkedHashSet
保存类似于列表
的排序,所以如果你把你的集合包裹在一个列表
当您想使用它作为列表
时,您将获得所需的语义。
There's no Java collection in the standard library to do this. LinkedHashSet
preserves ordering similarly to a List
, though, so if you wrap your set in a List
when you want to use it as a List
you'll get the semantics you want.
或者,对于通用版本,Commons Collections(或 collections15
)具有列表
你想要: SetUniqueList
。
Alternatively, the Commons Collections (or collections15
, for the generic version) has a List
which does what you want already: SetUniqueList
.
这篇关于那里有没有重复的List实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!