Are Hashtables not used anymore in Java?

Question from asianmalaysian vietnamese#1514

Are hashtables like not used anymore in java? Is its synchronicity for key value pairs not a beneficial thing?

Oh if someone asks where did I hear hashtables not being used anymore, in a different group in a different social media platform

They have been superseded.

People should now (generally) be writing code that targets the Map interface. If you want a synchronized map you can use Collections.synchronizedMap and if you want a good concurrent map there is ConcurrentHashMap.

That being said Hashtable isn't broken or anything. You can still use it if you want a synchronized map. It just comes from before the Java collections framework so the "default" we want to show people is HashMap and then how to synchronize whatever map they chose. So strictly speaking Hashtable is redundant.

got it, thanks!

same is true for Vector vs ArrayList also like,

Hashtable implements Map and extends Dictionary

Dictionary is this wierd abstract class that is basically an interface and some of its methods like keys() are redundant with keySet() on Map and also return Enumeration.

which is like iterator but without syntax support.

So yeah, just generally more crufty.


<- Index