Hashmap vs Array performance

前端 未结 7 1236
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 18:29

Is it (performance-wise) better to use Arrays or HashMaps when the indexes of the Array are known? Keep in mind that the \'objects array/map\' in the example is just an exam

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 19:23

    arrays when the indexes are know are faster (HashMap uses an array of linked lists behind the scenes which adds a bit of overhead above the array accesses not to mention the hashing operations that need to be done)

    and FYI HashMap objects = HashMap(); makes it so you won't have to cast

提交回复
热议问题