public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V>Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
LinkedHashMap:
LinkedHashMap is same like HashMap with additional feature of maintaining an insertion order of elements inserted into it.LinkedHashMap contains unique elements. This class provides all of the optional Map operations, and permits null elements. Like HashMap.
How does LinkedHashMap maintain insertion order?
LinkedHashMap implements Map interface extends HashMap class. its is base on Hash table and linked list implementation of the Map interface. It maintains a doubly-linked list all of its entries, in the map to maintain insertion order, in which they were inserted. This allows insertion-order iteration over the map. That is,when iterating through a collection-view of a LinkedHashMap, the elements will be returned in the order in which they were inserted.
Note: In LinkedHashMap, hashCode() is used to calculate the bucket and therefore calculate the index.
Note:- LinkedHashMap is good data structure to implement Least Recently Used (LRU) cache.
Related Tutorials
- Java Collections Interview
- Custom Own ArrayList Implementation
- List Interface In Java
- ArrayList
- LinkedList
- Set Interface In Java
- Map Interface In Java
- HashMap In Java
- HashMap Vs ConcurrentHashMap
- HashMap Vs HashTable In Java
- HashMap Vs HashSet In Java
- HashMap Vs TreeMap In Java
- HashMap vs LinkedHashMap In Java
- TreeSet Vs TreeMap In Java
- SortedSet Vs TreeSet In Java
- SortedMap Vs TreeMap In Java
- Array Vs ArrayList In Java
- ArrayList Vs LinkedList In Java
- How HashSet Works Internally
- How TreeMap Works Internally
- How HashMap Works Internally
- How ConcurrentHashMap Works Internally
No comments:
Post a Comment