Friday, January 16, 2009

Iterable Map Interface : Iterate over a map with keys and values.

Just about every map in the commons collection implements this interface. It allows you to iterate over the key and values with a MapIterator. I know that Java 1.5 has features that allow map iteration, but if you are 1.4... this is nice.

MapIterator it = aMap.mapIterator();
while (it.hasNext()) {
   key = it.next();
   value = it.getValue();
   out.println(key + " -> " + value);
}
Author: Philip A Senger

No comments:

Post a Comment