Premium Content - Free Preview

A Map is a data type which consists of a set of distinct keys that each map to a specific value.

A Map is also known as a Dictionary, since it can be used to store items in a similar manner as a dictionary, where each word maps to a specific definition. These are the basic methods of a Map:

  • put(key, value) - Adds the key and value to the map, so they are now associated with each other. If this key was already in the Map, it will now point to the new value only.
  • get(key) - Returns the value that the key maps to.
  • remove(key) - Removes the key-value mapping of this key from the map.
  • containsKey(key) - This returns true if the key is in the map and false otherwise (like the contains method of Set).

Maps vs. Lists

In a List (or Array), every item is stored at a specific index from 0 to N, the size of the List. Each item can be accessed by specifying the integer it is stored at.

End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Contact Us
Sign in or email us at [email protected]