Heres some code for declaring a new HashMap. Remember you will need to import the HashMap from java.util at the top of any Class that uses HashMaps.
And now heres adding a pair of values (Key first, then Value)
And heres how you can get the value which is associated with the key "Twig"
You must note that you need to typecast the reply from the HashMap when using get because it is like the ArrayList in that it forgets what type it was you put in to the HashMap.
The easiest way of thinking about HashMaps is to imagine a database with primary keys and a single field. The first value you enter is the key and the second is the data you want associated with the key. In the example above, the key is the name of a person and their telephone number is the data associated with the key. It would not make much sense to remember peoples telephone number to get their name!
One extremely important point is that, like ArrayLists, HashMaps store objects and not primative types like char, int, boolean and so on.