Java ListSet在哪里? [英] Java ListSet somewhere?

查看:152
本文介绍了Java ListSet在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找插入订单集合,同时允许高效查询和位置子集视图(如子列表)。看起来最直接的选择是采用List的链表方法,将节点嵌入为映射值,并暴露类的部分或全部列表接口。



有人会对甲骨文这么做吗?对于排序的地图和集合添加了NavigableMap / Set,并且没有更常见的插入顺序等效...



编辑:请不要建议LinkedHashSet - //docs.oracle.com/javase/6/docs/api/java/util/LinkedHashSet.htmlrel =nofollow> java.util.LinkedHashSet :


Set接口的哈希表和链表实现,
可预测的迭代顺序。这个实现不同于HashSet
,因为它维护一个双向链表,通过它的所有
条目。这个链表定义了迭代排序,它是元素被插入到集合(插入顺序)的
顺序。
请注意,如果元素将
重新插入到集合中,则插入顺序不会受到影响。 (如果s.contains(e)在
调用之前立即返回true,则调用s.add(e)是
时,元素e被重新插入到集合中。)



Looking for a insertion order collection that also allows efficient querying and subset views of positions (like sublist). Seems the most straightforward option for this would be to take the linked list approach of List, embed the nodes as map values and expose part or all of the list interface on the class.

Would someone bitch to Oracle about this? Having NavigableMap/Set added for sorted maps and sets and not having the far more common insertion order equivalent...

edit: please don't suggest LinkedHashSet - it doesn't have any way to query the position or to do a relative subset.

解决方案

you mean like java.util.LinkedHashSet:

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 ListSet在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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