What is the difference between a Hashtable and Properties?
HashMap is non-syncronized and is not thread safe while HashTable is thread safe and is synchronized. HashMap allows one null key and values can be null whereas HashTable doesn't allow null key or value. HashMap is faster than HashTable. HashMap iterator is fail-safe where HashTable iterator is not fail-safe.
A class can have multiple properties. For example, objects classified as computers have the following properties: Hardware ID, Manufacturer, Model, and Serial Number. The data schema defines the structure in which properties are stored and organizes the properties into classes.
Hashtable is a loosely typed (non-generic) collection, this means it stores key-value pairs of any data types. Dictionary is a generic collection. So it can store key-value pairs of specific data types.
Properties
is a very specialized class that's designed to hold configuration and/or resources that are usually stored in some file.
It has several features that Hashtable
doesn't have (and shouldn't have):
load()
/store()
)loadFromXML()
/storeToXML()
)Properties
instance at construction time.String
keys and values. While it is technically a Map<Object,Object>
actually storing non-String
keys or values is strongly discouraged and unsupported.A Hashtable
on the other hand is a general-purpose Map
implementation (which is mostly replaced by the HashMap
, however).
Properties is a subclass of Hashtable, and it is designed for string to string mappings. It also adds the ability to store the mapping into a text file, and read it back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With