Memory overhead of Java HashMap compared to ArrayList

后端 未结 13 1830
不知归路
不知归路 2020-11-30 02:15

I am wondering what is the memory overhead of java HashMap compared to ArrayList?

Update:

I would like to improve the speed for searching fo

13条回答
  •  离开以前
    2020-11-30 02:36

    If you're considering two ArrayLists vs one Hashmap, it's indeterminate; both are partially-full data structures. If you were comparing Vector vs Hashtable, Vector is probably more memory efficient, because it only allocates the space it uses, whereas Hashtables allocate more space.

    If you need a key-value pair and aren't doing incredibly memory-hungry work, just use the Hashmap.

提交回复
热议问题