Map

A Map pairs keys and values. If we want to approach a Map from the Collection point of view then a Map is a set of key/value pairs. You can put key value pairs into a Map and you can get a value based on a key. Keys are unique the same way as elements in a Set. If you look at the source code of the different implementations of the Set interface, you may see that some of them are implemented as a wrapper around a Map implementation where the values are simply discarded.

Using Maps is easy and alluring. Many languages, such as Python, Go, JavaScript, Perl, and so on, support this data structure on the language level. However, using a Map when an array would be sufficient is a bad practice that I have seen many times, especially in scripting languages. Java is not prone to that novice programmer error but you may still find yourself in a situation when you want to use a Map, and still there is a better solution. It is a general rule that the simplest data structure should be used that is sufficient for the implementation of the algorithm.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.123.155