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 性能我是正确的


基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13