Maps (aka Dictionaries)
Reading
- Please read about Map and HashMap.
- You do not need to do the programming exercises in the reading, but you may find it helpful to try them a little. It’s up to you.
Important concepts
- Map data structure (also called a dictionary or associative array in other languages)
- Keys vs values, key-value pairs
Things to consider (exercises for yourself, not to turn in)
- The Java
Map
interface has theget()
method for looking up the value that corresponds to a given key. Why isn’t there a method that goes in the other direction, i.e. looking up the key that corresponds to a given value? - Is there a situation where
containsKey(x)
could returntrue
, but thenget(x)
returnsnull
? (Yes! What is it?)
Your response
What do you hope to learn about maps from the in-class activity?