Category Archives: Map

Create least recently used (LRU) cache in java using LinkedHashMap

LRU is one of the most popular caching algorithm. The items, which are least recently used are removed from the cache, using eviction policy. Types of iteration order in LinkedHashMap: Insertion order: This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map Access order:  Access order is… Read More »

Access order in LinkedHashMap using java (with example)

LinkedHashMap have following attributes: LinkedHashMap is Hashtable and LinkedList based implementation of Map interface. By default LinkedHashMap maintains the insertion order (i.e. the order in which elements are added to LinkedHashMap is maintained.) LinkedHashMap has special constructor to create the access order map. Keys are sorted on the basis of access order e.g Invoking the put, putIfAbsent, get,… Read More »

Insertion order in LinkedHashMap using java (with example)

LinkedHashMap has following attributes. LinkedHashMap maintains the insertion order. The default mode is insertion order. The order in which elements are added to LinkedHashMap, is maintained LinkedHashMap is Hashtable and LinkedList based implementation of Map interface. Constructors of LinkedHashMap are as follows: LinkedHashMap() Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and… Read More »

Put,Remove,Sort,iterate,Get & other methods of HashMap (example)

What is HashMap in java? HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations (get and put). HashMap based implementation is not thread safe. HashMap must synchronized externally, If multiple threads access a hashmap concurrently. Program to demonstrate following methods of HashMap. Remove put Sort Iterate Get Contains And… Read More »

putIfAbsent method of HashMap in java (with example)

HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations (get and put). HashMap based implementation is not thread safe. HashMap must synchronized externally, If multiple threads access a hashmap concurrently putIfAbsent method is defined in Map interface. putIfAbsent method is used to add entry to HashMap, if its not… Read More »

Page 1 of 212