How is the implementation of LinkedHashMap different from HashMap?

前端 未结 8 1262
故里飘歌
故里飘歌 2020-12-28 12:07

If LinkedHashMap\'s time complexity is same as HashMap\'s complexity why do we need HashMap? What are all the extra overhead LinkedHashMap has when compared to HashMap in Ja

8条回答
  •  一向
    一向 (楼主)
    2020-12-28 12:40

    LinkedHashMap will take more memory. Each entry in a normal HashMap just has the key and the value. Each LinkedHashMap entry has those references and references to the next and previous entries. There's also a little bit more housekeeping to do, although that's usually irrelevant.

提交回复
热议问题