Why do I get an OutOfMemoryError when inserting 50,000 objects into HashMap?

前端 未结 10 2030
猫巷女王i
猫巷女王i 2021-02-01 08:12

I am trying to insert about 50,000 objects (and therefore 50,000 keys) into a java.util.HashMap. However, I keep getting an OutOfMemo

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 08:54

    Random thought: The hash buckets associated with HashMap are not particularly memory efficient. You may want to try out TreeMap as an alternative and see if it still provide sufficient performance.

提交回复
热议问题