I am a long time user of Python and really like the way that the dictionaries are used. They are very intuitive and easy to use. Is there a good Java equivalent to python's dictionaries? I have heard of people using hashmaps and hashtables. Could someone explain the similarities and differences of using hashtables and hashmaps versus python's dictionaries?
Python's dict class is an implementation of what the Python documentation informally calls "mapping types". Internally, dict is implemented using a hashtable. Java's HashMap class is an implementation of the Map interface. Internally, HashMap is implemented using a hashtable.
In Java, Dictionary is the list of key-value pairs. We can store, retrieve, remove, get, and put values in the dictionary by using the Java Dictionary class.
Yes, it is a hash mapping or hash table. You can read a description of python's dict implementation, as written by Tim Peters, here.
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.
Python's dict
class is an implementation of what the Python documentation informally calls "mapping types". Internally, dict
is implemented using a hashtable.
Java's HashMap
class is an implementation of the Map
interface. Internally, HashMap
is implemented using a hashtable.
There are a few minor differences in syntax, and I believe the implementations are tuned slightly differently, but overall they are completely interchangeable.
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