Thread: what is hashmap
View Single Post
  #2 (permalink)  
Old 07-28-2007, 12:28 AM
brianhks brianhks is offline
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
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"
Reply With Quote