HashMap: HashMap allows 0(1) lookup and addition. It is implemented by an array of associated lists.
Syntax:
public class HashMap extends AbstractMap
implements Map, Cloneable, Serializable
- A HashMap includes values based on the key.
- It holds unique elements.
- It may have one null key and many null values.
- It has no order.
LinkedHashMap: LinkedHashMap gives 0(1) lookup and addition. Keys are commanded by their insertion position. It is executed by doubly-linked buckets.
Syntax:
public class LinkedHashMap extends HashMap
0implements Map
- A LinkedHashMap holds values based on the key.
- It holds unique elements.
- It may have one null key and many null values.
- It is the same as HashMap rather than preserves the insertion order.
TreeMap: TreeMap gives O(log N) lookup and addition. Keys are commanded, so if you need to iterate over the keys in sorted order, you can. This means that keys need to implement the Comparable interface. TreeMap is executed by a Red-Black Tree.
Syntax:
public class TreeMap extends AbstractMap implements
NavigableMap, Cloneable, Serializable
- A TreeMap holds values based on the key. It performs the NavigableMap interface and extends AbstractMap class.
- It holds unique elements.
- It can't have a null key but can have multiple null values.
- It is the same as HashMap rather maintains ascending order(Sorted using the original order of its key).