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

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

问题描述

我知道 SortedSet,但就我而言,我需要实现 List 而不是 Set 的东西.那么在 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?

实现我自己应该不难,但我想为什么不先问这里的人?

It shouldn't be hard to implement myself, but I figured why not ask people here first?

推荐答案

标准库中没有 Java 集合来执行此操作.LinkedHashSet 保留类似于 List 的顺序,因此如果您想将它用作 List 时将其包装在 List 中你会得到你想要的语义.

There's no Java collection in the standard library to do this. LinkedHashSet<E> 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(或commons-collections4,对于通用版本)有一个 List 已经可以满足您的需求:SetUniqueList/SetUniqueList.

Alternatively, the Commons Collections (or commons-collections4, for the generic version) has a List which does what you want already: SetUniqueList / SetUniqueList<E>.

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

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