Java EnumMap is a Java Map that uses keys of a single enum type. EnumMap utilizes the inherent associative nature of arrays and is therefore the most efficient implementation of Map. In a nutshell, EnumMap is a one-trick-pony designed to be used when the keys of your Map are constants and therefore can be made static and final. Constructors of EnumMap… Continue reading Java EnumMap with Example
Tag: Dictionary
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