HashTable Benefits

What is the main advantage of using Hashtablecompared to HashMap. Because the Hashtablemain advantage is synchronization. Now the card can also sync with synchronizedMap().

Map m = Collections.synchronizedMap(hashMap);
+5
source share
2 answers

Hashtableexisted before collections, so it is saved mainly for backward compatibility. Use instead ConcurrentHashMap.

Please note that there is a small semantic difference - it Hashtabledoes not allow null values, but HashMapallows null values ​​and a null key.

+3
source

HashTable . , HashTable , HashMap - . , , , HashTable , .

, , HashTable , - , - , , :

if(key does not exist)
    add key

, , . .

, HashTable ...

+2

All Articles