LinkedHashMap Example: LRU Cache Implementation

LRU cache can be implemented fairly easily using LinkedHashMap. In this article we examine what is LRU cache and how to implement it in Java. What is LRU Cache? LRU cache stands for least-recently-used cache. Before we examine the LRU policy, let’s take a moment to see what a cache is. What is a cache? In… Continue reading LinkedHashMap Example: LRU Cache Implementation

LinkedHashMap with Example

LinkedHashMap is a sub-class of Java HashMap with capabilities to keep keys ordered either in insertion order or access order. LinkedHashMap is the dictionary/table implementation of choice whenever you want best performance and predictable key ordering at the same time. It achieves this magical feat by maintaining a doubly linked list apart from the usual implementation of HashMap. The doubly-linked list is used to… Continue reading LinkedHashMap with Example

Java HashMap with Example

Java HashMap is the most popular concrete implementation of Java Map. The distinguishing feature of HashMap is that it is based on the celebrated hashtable data structure. Like any other Java Map, a HashMap maintains associations between keys and values. A HashMap is an unordered collection, meaning you should not use HashMap if your program requires iteration or retrieval in a predictable order. Nevertheless, a HashMap is extremely efficient… Continue reading Java HashMap with Example