I've always used dictionaries. I write in Python.
In Hashtable, you can store key/value pairs of the same type or of the different type. In Dictionary, you can store key/value pairs of same type. In Hashtable, there is no need to specify the type of the key and value. In Dictionary, you must specify the type of key and value.
A dictionary is a general concept that maps unique keys to non-unique values. But the Hash is a data structure that maps unique keys to values by taking the hash value of the key and mapping it to a bucket where one or more values are stored.
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.
In Java the HashMap implements the Map interface while the Dictionary does not. That makes the Dictionary obsolete (according to the API docs). That is, they both do a similar function so you are right that they seem very similar...a HashMap is a type of dictionary. You are advised to use the HashMap though.
A dictionary is a general concept that maps keys to values. There are many ways to implement such a mapping.
A hashtable is a specific way to implement a dictionary.
Besides hashtables, another common way to implement dictionaries is red-black trees.
Each method has it's own pros and cons. A red-black tree can always perform a lookup in O(log N). A hashtable can perform a lookup in O(1) time although that can degrade to O(N) depending on the input.
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