Skip to main content

HashMap in Java


1) Implement HashMap in Java, with the put and get operations

  HashMap can be implemented in Java Using Arrays. Use the same logic that the Out of the Box
  HashMap follows, for resizing, and load factor, when ever the HashMap reaches the size of the
  resize with the load factor a new Array is created, and the previous array contents are copied over
  to the new Array.

 HashMap is Not Synchronized by default. We can synchronize the whole map by using Synchronization, or by using collection.synchronizedmap(map), which synchronizes all the operations on the map. Alternatively We can use the CocurrentHashMap which does not lock the
read operations, rather locks the segments that are being written.



2) HashMap vs LinkedHashMap vs IdentityHashMap


3) HashMap vs ConcurrentHashMap


4) Implement a Cache using LinkedHashMap








Comments

Popular posts from this blog

Design Patterns using Java

According to Gang of Four(GOF) any software is classified in to one of the three categories. I read so many books about design patterns which provide a lot of information about Design Patterns in a language neutral way or related to a particular programming language. I am trying to complement the great books by providing the precise and concise information that is required in the day to day programming of a Java Developer. Any software can be classified into one of the three categories -Framework, Toolkit, Application. Framework - Framework defines a set of steps to create an application. Framework provides design reuse. Toolkit - Toolkit provides some utility functions to an existing application. Toolkit provides code reuse. Application - Application is some thing that is specific to the project, and is not useful outside the context of the current application. Gang of Four divided the Design Patterns in to 3 types based on their usage. There are 3 types of Gang of Fo