posted 21 years ago
A key is something like a postal address and a value like a package that is located there. Using an array you could think of an array index as being a key and whatever is stored at that index as a value. For example:
In the code above, using the array analogy, the key is 1 (the subscript) and the value is 2, so the variable i is set to 2. Here is the way you could do the same thing with a Map:
That code is a lot messier than the first, but it shows the relationship between keys and values. The real power of a Map though is the ability to associate any object key to any object value. For example, say we have a group of students with average grades and we want to associate the student's name with the grade:
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher