有没有重复的列表实现吗? [英] Is there a no-duplicate List implementation out there?

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

问题描述

我知道 SortedSet ,但在我的情况下,我需要一个实现 List ,而不是设置

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 虽然保留了与 List 类似的排序,所以如果你将你的集合包装在列表当你想使用它作为一个列表,你会得到你想要的语义。

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.

或者,共享集合(或 collections15 ,对于通用版本)有一个 List 您希望已经: SetUniqueList

Alternatively, the Commons Collections (or collections15, for the generic version) has a List which does what you want already: SetUniqueList.

这篇关于有没有重复的列表实现吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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