Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Hashtable and Dictionary?

Tags:

What's the difference between Dictionary and Hashtable and how do I work with the Dictionary class in Java?

like image 891
Samir Mangroliya Avatar asked Mar 19 '12 12:03

Samir Mangroliya


People also ask

Is Hashtable better than dictionary?

A Dictionary<TKey,TValue> of a specific type (other than Object) provides better performance than a Hashtable for value types. This is because the elements of Hashtable are of type Object; therefore, boxing and unboxing typically occur when you store or retrieve a value type.

Is a Python dictionary the same as a hash table?

In Python, dictionaries (or “dicts”, for short) are a central data structure: Dicts store an arbitrary number of objects, each identified by a unique dictionary key. Dictionaries are often also called maps, hashmaps, lookup tables, or associative arrays.

What is the difference between dictionary and HashMap?

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.

Is hash table faster than dictionary?

Dictionary is a generic type and returns an error if you try to find a key which is not there. The Dictionary collection is faster than Hashtable because there is no boxing and unboxing.


1 Answers

Dictionary is an abstract base class of Hashtable. Both are still in JDK for backwards compatibility with old code. We are expected to use HashMap and other implementations of Map interface introduced in Java 1.2.

like image 153
AlexR Avatar answered Oct 30 '22 07:10

AlexR