HashMap vs ArrayList performance am I correct

后端 未结 6 2035
野趣味
野趣味 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条回答
  •  Happy的楠姐
    2020-12-04 10:08

    Don't forget it's also much faster to get to one specific item with a map (if you have the key) than it is from an array (unless you have an index, but a key will always get you the right value whereas having an index may not work if new elements are inserted or older ones removed).

提交回复
热议问题