维护插入顺序的Java集合 [英] Java collections maintaining insertion order

查看:292
本文介绍了维护插入顺序的Java集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么一些集合数据结构不保持插入的顺序?与维持插入顺序相比,特殊的事情是什么?
如果我们不维护订单,我们会获得什么吗?

Why do some collection data structures not maintain the order of insertion? What is the special thing achieved compared to maintaining order of insertion? Do we gain something if we don't maintain the order?

推荐答案

如果你想要原始的插入顺序,有LinkedXXX类,它们在插入顺序中维护一个额外的链表。大多数时候你不在乎,所以你使用HashXXX,或者你想要一个自然的顺序,所以你使用TreeXXX。在任何一种情况下,为什么你应该支付链接列表的额外成本?

Performance. If you want the original insertion order there are the LinkedXXX classes, which maintain an additional linked list in insertion order. Most of the time you don't care, so you use a HashXXX, or you want a natural order, so you use TreeXXX. In either of those cases why should you pay the extra cost of the linked list?

这篇关于维护插入顺序的Java集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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