HashMap vs ArrayList performance am I correct

后端 未结 6 2041
野趣味
野趣味 2020-12-04 09:29

I currently believe that:

  • When you need a structure from which you will be retrieving items randomly - use a HashMap
  • When you will be ret
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 10:05

    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.

    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.

提交回复
热议问题