Get the most important things about HashTable in Java
A hash table is a data structure that is used to store keys/value pairs.
The primary interface for hashtable in java JDK is Map.
A map cannot contain duplicate keys. Each key can map to at most one value.
That means if we add the first employee jack with key “smith” and the employee kamal with key “smith”,that means we will replace the first employee which is jack with kamal. Their will just one employee with key smith.
A lot of class implement the Map, they are used under certain circumstances.
One of them is HasheMap, it provides all of the optional map operations, and permits null values and the null keys.
It provides constant time complexity for basic operations.
But, this implementation is not synchronized.
One of the HashMap sub-classes is LinkedHashMap. it does not mean that it is backed by Linkedlist.It is backed by an array,and it is not synchronized.
One of the benefits of LinkedHashMap, is removeEldestEntry() method,which can be used to remove the oldest entry every time we add a new one.
For HashTable , it Cannot add null keys and values, everything has to be non-null.And it is very useful for concurrent processing, because it is synchronized.
This is an example of hashTable using HashMap class: here