Any implementation of Ordered Set in Java?(Java中有序集的任何实现?)
问题描述
如果有人熟悉 Objective-C,那么有一个名为 NSOrderedSet
充当 Set,其项目可以作为 Array 的项目访问.
If anybody is familiar with Objective-C there is a collection called NSOrderedSet
that acts as Set and its items can be accessed as an Array's ones.
Java 中有这样的东西吗?
Is there anything like this in Java?
我听说有一个集合叫做 LinkedHashMap代码>,但我还没有找到类似的集合.
I've heard there is a collection called LinkedHashMap
, but I haven't found anything like it for a set.
推荐答案
看看LinkedHashSet 类
来自 Java 文档:
From Java doc:
Set 接口的哈希表和链表实现,具有可预测的迭代顺序.此实现与 HashSet 的不同之处在于它维护一个双向链表,该列表贯穿其所有条目.这个链表定义了迭代顺序,元素被插入到集合中的顺序(insertion-order).请注意,如果将元素重新插入集合中,插入顺序不会受到影响.(如果在调用 s.contains(e) 将在调用之前立即返回 true 时调用 s.add(e),则元素 e 将重新插入到集合 s 中.).
Hash table and linked list implementation of the Set interface, with predictable iteration order. This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order). Note that insertion order is not affected if an element is re-inserted into the set. (An element e is reinserted into a set s if s.add(e) is invoked when s.contains(e) would return true immediately prior to the invocation.).
这篇关于Java中有序集的任何实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java中有序集的任何实现?
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01