HashMap is generally preferred over HashTable if thread
synchronization is not needed
- HashMap is non synchronized (not-thread safe and can't be
shared between many threads whereas Hashtable is synchronized. It is
thread-safe and can be shared with many threads.
- HashMap allows one null key and multiple null values whereas
Hashtable doesn't allow any null key or value.
Which algorithm has the best asymptotic runtime
Bubble Sort and Insertion Sort has fair runtime
complexity. Heapsort is bad. Selection Sort is Horrible.
Bucket Sort, Radix Sort and Counting Sort are the best runtime
More details please check
Difference between Synchronized HashMap and
ConcurrentHashMap -No need to lock the map to
read a value. SynchronizedHashMap - lock is required for read
ConcurrentHashMap doesn't throw a ConcurrentModificationException
if one thread tries to modify it while another is iterating over it.
The iterator reflects the state of the map at the time of it's
creation. SynchronizedHashMap returns Iterator, which fail-fast on
ConcurrentHashMap - multiple threads can add/remove
SynchronizedHashMap - only one thread is allowed to make change.
What is mean by fail-fast and fail-safe iterators
All the time, we iterator collection but we ignor what
called in java terms. Fail-safe iterators means they will not
throw any exception even if the collection is modified while
iterating over it.
Fail-fast iterators throw an ConcurrentModificationException if
the collection is modified while iterating over it.