Listing B
// Listing B /** * @return Iterator filled with Strings representing user names */ public Iterator getUsers() { final ResultSet rs = userDbQuery(); return new Iterator() { private Object next; public boolean hasNext() { if (next == null) { if (! rs.next()) { return false; } next = rs.getString(1); } return true; } public Object next() { if (! hasNext()) { throw new NoSuchElementException(); } String retval = next; next = null; return retval; } public void remove() { throw new UnsupportedOperationException("no remove allowed"); } } }