HashMap vs ArrayList performance am I correct(HashMap vs ArrayList 性能我是正确的)
问题描述
我目前认为:
- 当您需要一个从中随机检索项目的结构时 - 使用
HashMap
- 当您将按顺序检索项目时(例如使用 for 循环) - 使用
ArrayList
我通常是正确的吗?是否存在不正确的情况?
Am I generally correct? Are there situations where this is not correct?
推荐答案
一般来说,是的,你是对的.还有一个组合数据结构,LinkedHashMap,它提供对任意元素的快速访问以及可预测的排序.
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 接口的两种实现.每个都有其他实现可能更适合更具体的要求.例如,对于某些排队/出队要求,LinkedList 可能比 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 vs ArrayList 性能我是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:HashMap vs ArrayList 性能我是正确的


基础教程推荐
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01