|
A Map is like a dictionary in other languages. You have a key and you lookup a value using that key. Java has two kinds of Map's HashMap and TreeMap. The HashMap uses a hash of the key for lookups whereas the TreeMap uses a binary tree for storing the keys.
HashMap<String, String> myMap = new HashMap<String, String>();
myMap.put("FirstKey", "Bob");
myMap.put("SecondKey", "Sam");
System.out.println(myMap.get("FirstKey"));
This code should print out "Bob"
|