Note on Some Important Terms
| Parameter | Hashmap | Hashtable |
|---|---|---|
| Synchronized | Not Syncronized | Syncronized |
| Null key and Value | Allows one null key and any number of null values | Not allow null keys or values |
| Fail fast | Iterator in Hashmap is fail fast | Enumeration in Hashtable is not fail fast |
| ThreadSafe | No | Yes |
| Extends | Extends AbstractMap class | Extends Dictionary class |
| Performance | Faster then Hashtable | Slower then Hashmap |
Note – You can synchonized a HashMap with the help of Collections.synchonizedMap(hashmap)
Map map=Collections.synchonizedMap(hashmap)
Syncronized →Being synchronized means that operation is thread safe, so only one thread can access the table at a time.
Fail safe – Fail-fast means when you try to modify the content when you are iterating, it will throw ConcurrentModification Exception and fail immediately.
For HashMap Itration:
Set keys = hashMap.keySet();
for (Object key : key) {
hashMap.put(someObject, someValue); //it will throw the ConcurrentModificationException
}
For HashTable Enumeration:
Enumeration keys = hashTable.keys();
for (Enumeration e = v.elements() ; e.hasMoreElements() ; e.nextElement()) {
hashTable.put(someKey, someValue); //it works
}
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…