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

查看:22
本文介绍了维护插入顺序的 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天全站免登陆