Iterators as interface


Map params = request.getParameterMap();
...
for(Iterator i =
      getParameter(params, "some-parameter");
    hasNext(); )
{
  String s = (String)i.next();
  ...
}
Better? Clearer? I think so. So what's behind the curtain?

Even though a previous bit of code wasn't outrageously onerous, I think this is nicer. There's no explicit check for null, and we're not having to deal with an array. The intent is clearer, because we know what happens with an iterator. (We start at the one end and churn to the other ...)