In cases where you need a key-value data-structure. For instance HashMaps are often used for lookup. E.g. you've got a person-id and with the HashMap (or an other Map implementation) you can lookup the corresponding Person object. You could iterate through a List but the performance of a HashMap is much better.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Think of Map like table of contents where there is a mapping between Chapter and its page number. So if you wanted to read what is there is Chapter 5, you can gets it page number from Map and directly go there.
If you are using a Vector or List, you would have to browse through Chapters 1-4 to reach Chapter 5.
HashMap is famous for its algorithm called *hashing*. this technique is very fast for adding and finding/retrieving an element in the array
Joined: Jun 17, 2011
Thank you to everyone for your replies, this is helping.
When retrieving information from a map, is the goal to get an array index or the actual corresponding value? I suppose one would look for 1) presence: if the item you are looking for is really there and then 2) the matching value.