How is the implementation of LinkedHashMap different from HashMap?

Passionate programmer picture Passionate programmer · Jun 11, 2010 · Viewed 20k times · Source

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?

Answer

Jon Skeet picture Jon Skeet · Jun 11, 2010

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.