Hashtables vs HashMaps Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Synchronization?

A

HashMap is non-synchronized. This means if it’s used in multithread environment then more than one thread can access and process the HashMap simultaneously.

Hashtable is synchronized. It ensures that no more than one thread can access the Hashtable at a given moment of time. The thread which works on Hashtable acquires a lock on it to make the other threads wait till its work gets completed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Null Values?

A

HashMap allows one null key and any number of null values. Hashtable doesn’t allow null keys and null values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Ordering?

A

HashMap implementation LinkedHashMap maintains the insertion order and TreeMap sorts the mappings based on the ascending order of keys.

Hashtable doesn’t guarantee any kind of order. It doesn’t maintain the mappings in any particular order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Collections?

A

Initially Hashtable was not the part of collection framework. Tt has been made a collection framework member later after being retrofitted to implement the Map interface.

HashMap implements Map interface and is a part of collection framework since the beginning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fail-fast?

A

The Iterator of the HashMap is a fail-fast and it throws ConcurrentModificationException if any other Thread modifies the map structurally by adding or removing any element except iterator’s own remove() method. In Simple words fail-fast means: When calling iterator.next(), if any modification has been made between the moment the iterator was created and the moment next() is called, a ConcurrentModificationException is immediately thrown.

Enumerator for the Hashtable is not fail-fast.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly