Skip to main content

Difference between HashMap, LinkedHashMap and TreeMap


 LinkedHashMap is an implementation of java.util.Map interface with predictable iteration order (the order of insertion) i.e. LinkedHashMap will iterate in the order in which the entries were put into the map.
LinkedHashMap implementation differs from HashMap in the way that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map. The insertion order is not affected if a key is re-inserted into the map. Performance of LinkedHashMap is slightly below than that of HashMap, due to the added expense of maintaining the linked list.

The other two important implementations of Map interface are java.util.HashMap and java.util.TreeMap. They offer mostly the same functionality. The most important difference is the order in which iteration through the entries will happen. HashMap makes no guarantee about the order. The order can even change completely when new elements are added. TreeMap will iterate according to the “natural ordering” of the keys according to their compareTo() method (or an externally supplied java.util.Comparator). LinkedHashMap will iterate in the order in which the entries were put into the map.

Apart from these three popular Map implementation, you also have some special purpose Map implementations e.g. EnumMap for storing mapping with enum constants as keys,  it is highly optimized for enum constants. You also have a special map called WeakHashMap for creating a Garbage Collector friendly Cache, where values become eligible for garbage collection as soon as there is no other reference to them apart from keys in WeakHashMap.

Then there is IdentityHashMap for creating a Map which uses identity instead of equality for comparing keys since identity equality is rare, you get less number of collisions on this Map and finally, ConcurrentHashMap is much better for scalability in a multi-threaded environment, where the number of reader threads clearly outnumbers a number of writer threads.

Popular posts from this blog

How To Install the Anaconda Python Distribution on Debian 9 And Running a public notebook server

Anaconda Distribution is an open-source package manager, environment manager and distribution of Python and R programming languages. With a collection of 1,000+ open source packages with free community support. Designed for data science and machine learning workflows, you can use it whether you are on Windows, macOS or Linux. The Anaconda distribution ships with the conda command-line package management utility. You can learn more about Anaconda and conda by reading the official Anaconda Documentation . Jupyter is a browser-based interpreter that allows you to interactively work with Python and R. Anaconda provides Jupyter as well. You can think of Jupyter as a digital notebook that gives you an ability to execute commands, take notes and draw charts.It’s primarily used by Data Scientists. But I find that very useful tool if you are learning Python or R. It’s basically the same as working on a shell but much better. The Jupyter notebook web application is based on a...

django react app setting up the backend

On the previous article I demonstrated how we can use the generic views along with ModelSerializer classes to rapidly develop our REST APIs. Knowledge that you will need  in your career as full stack / backend developer, however think of this article as an extension to the previous one, equipped with what we already know about REST API we will step our game up and discuss about ViewSet, ModelViewset we will dig deep into the concepts of Routers which allow us to manage our api routes in a simple and sophisticated manner as well as helping to speed up building APIs even further. There for on part II of this article i'll work you through on how React application can consume this RESTful API. There for at the end of the day we will have a full stack web app, in short we strat our development at the backend then later on we move at the frontend... so are you excited and ready to take the challange? lets do this then..... you can get source code for the bakend on github Preparat...

Beginner's Guide to React, how to consume a RESTful API in React

Intro (Skit) First and foremost I would like to apologize for making you wet wait this hook took long than it should have. Starving just got the best of striving, on the way some will React...  don't we like it when a flower or a little tuft of grass grows through a crack in the concrete. It's so fuckin heroic. Interlude: Wake up and smell the dour time for an early session seeks to serialize and give examples Shebang as much as I would love to django I need to lay back Head stash the size of the pillow I rest my head on restful and node, just to appreciate the script front to back back 2 back too back frontin react crud crud My depositions never surface and that's the 20/20 ishy const args kwargs we don't cors these lines we inhale these lines that's a callback function for your queryset you dig. Let's get the basics out of the way. React is not another MVC framework or any other kind of framework. It's just a library for rendering your views...