本文介绍了LinkedHashMap的实现与HashMap有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果LinkedHashMap的时间复杂度与HashMap的复杂度相同,为什么需要HashMap?与Java中的HashMap相比,LinkedHashMap具有哪些额外开销?

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 Java?

推荐答案

LinkedHashMap将占用更多内存。正常 HashMap 中的每个条目都只有键和值。每个 LinkedHashMap 条目都具有对下一个和前一个条目的引用引用。还有一点点家务要做,虽然这通常是不相关的。

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.

这篇关于LinkedHashMap的实现与HashMap有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 10:46