HashMap的ArrayList的VS性能我是正确的 [英] HashMap vs ArrayList performance am I correct

查看:146
本文介绍了HashMap的ArrayList的VS性能我是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前认为:


  • 当你需要从中你将随机检索项的结构 - 使用的HashMap

  • 当你为了(例如,使用一个for循环)来获取项目 - 使用的ArrayList

  • When you need a structure from which you will be retrieving items randomly - use a HashMap
  • When you will be retrieving items in order (e.g. using a for loop) - use an ArrayList

我是通常是正确的?有没有情况下这是不正确的?

Am I generally correct? Are there situations where this is not correct?

推荐答案

一般情况下,是的,你是正确的。还有一个组合的数据结构, LinkedHashMap的,该报价快速访问任意元素以及predictable排序。

Generally, yes, you are correct. There's also a combined data structure, the LinkedHashMap, which offers fast access to arbitrary elements as well as predictable ordering.

不过,值得注意的是,ArrayList和HashMap的分别只有两个List和Map接口的实现。有每个可能更适合于更具体的要求的其他实现。例如,一个链表可能比某些排队/出队的要求一个ArrayList提供更高的性能。

However, it's worth noting that ArrayList and HashMap are only two implementations of the List and Map interfaces, respectively. There are other implementations of each that might be more suitable for more specific requirements. For example, a LinkedList might provide higher performance than an ArrayList for certain queueing/dequeueing requirements.

这篇关于HashMap的ArrayList的VS性能我是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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