The map or dictionary data type, stores key/value pairs and can be thought of as a real dictionary. You associate word/definition pairs with a dictionary. With the map container, the word is the key, and the definition is the associated object that you want to store. Like a list, a map can grow dynamically as you add more pairs of key/values to it. It also allows you to "look up" a value for a given key.
Dictionaries are particularly useful when you need to store data that will be looked up again and again. Suppose you are creating a new object-oriented dictionary and would like to use a map data type to store your definitions.
The key value pairs for your dictionary could look something like this:
lasting a small amount of time
measuring a great distance from end to end
at the present time or moment
Acme Egg Company social media
Acme Egg Company would like you to develop a comments page that will allow customers to give feedback. Customer have something to say and they want to constantly improve the egg operations. Here is what they have told us so far:
Customers can enter several comments per day.
They want to comments to be logged by when they were posted.
To do this, you could create a key containing the year, month, then the day the comment was posted. Your value would then be the text of the comment itself. It could look something like:
I purchase eggs from this firm every Tuesday and the service is always the greatest!
Their sales department is the best I’ve seen. I purchase from many corporations and this shipping system is wonderful.
The grade A large eggs are the best we have tasted. We also use them for baking cakes.
You can add on as many of these comments as you need, but if you find out some of the comments are from co-workers joking around, you can delete those! A dictionary is flexible that way. 😉
The map or dictionary data type stores rows of key/value pairs.
Rows can be added/removed for any key you wish.
Size is dynamic, and can shrink/grow in real time.