HashMap:
public class HashMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Serializable
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
Direct Known Subclasses:
LinkedHashMap, PrinterStateReasons
LinkedHashMap:
public class LinkedHashMap<K,V>
extends HashMap<K,V>
implements Map<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
Similarities between HsahMap and LinkedHashMap
- Iterator returned by HashMap and LinkedHashMap are fail-fast.
- HashMap and LinkedHashMap both are similar in terms of performance.
- HashMap and LinkedHashMap both are not synchronized. that means not thread safe.
Difference between HsahMap and LinkedHashMap
HsahMap | LinkedHashMap |
---|---|
HsahMap | LinkedHashMap |
HsahMap was introduced in JDK 2.0. | LinkedHashMap was introduced in JDK 4.0. |
HsahMap uses the HashTable to store entries. | LinkedHashMap uses the HashTable and doubly Linked List to store entries. |
HashMap does not maintain the insertion order. | LinkedHashMap maintains the insertion order of elements. |
HsahMap has a relatively low overhead. | LinkedHashMap has a relatively higher overhead.Because it maintain the order of entries |
HsahMap extends the AbstractMap and implements Map interface. | LinkedHashMap extends the Hashmap and implements Map interface that means it is sub-class of HashMap. |
HsahMap requires less memory space compared to LinkedHashMap. | LinkedHashMap requires more memory space compared to HashMap because of it maintain the order of entries.Internally LinkedHashMap uses doubly Linked List to maintain order of elements. |
Re-entering(updating value of existing key) a value does not change the insertion order of the LinkedHashMap. | |
HashMap has constant-time performance O(1) for most operations like put(), get(), remove() and contains(). | LinkedHashMap has complexity of O(1) for put(), get(), remove() and contains(). |
Related Tutorials
- Java Collections Interview
- List Interface In Java
- ArrayList
- LinkedList
- Custom Own ArrayList Implementation
- Custom LinkedList implementation in java
- Set Interface In Java
- Map Interface In Java
- HashMap
- TreeMap
- 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
- How To Detect Loop In A LinkedList In Java
- Detect And Remove Loop In A LinkedList
No comments:
Post a Comment