Tuesday, October 26, 2004

hash map iteration

code snippet for iterating over a hash:

HashMap map = new HashMap();
map.put("key1", "value1");
map.put("key2", "value2");
// the only method of iterating over a list
for (Iterator i = map.keySet().iterator(); i.hasNext();) {
String key2 = (String) i.next();
String value2 = (String) map.get(key2);
System.out.println(key2 + value2);

}