Java 中有序集的任何实现? [英] Any implementation of Ordered Set in Java?

查看:30
本文介绍了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 的不同之处在于它维护一个双向链表,贯穿其所有条目.这个链表定义了迭代顺序,元素被插入到集合中的顺序(插入顺序).请注意,如果将元素重新插入到集合中,则插入顺序不会受到影响.(如果在调用 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 中有序集的任何实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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