A HashMap is a table that holds a collection of key-value pairs. It “maps” numerous keys to their respective values. A HashMap is very similar to a dictionary. In a dictionary, you might want to look up a definition for a certain word. You simply look up the keyword in the dictionary and by doing so, you can get the definition attached to that keyword. The dictionary maps words (the “keys”) to their definition (the “values”).
HashMaps can store many different types of information. The one below stores people as the key and their order as the value.
We want to be able to directly access someone’s order the same way we would find a definition in a dictionary. By looking up “Bea”, the HashMap returns her order: Arepas. We will look at some common HashMap methods in the next page.