Skip to content

Instantly share code, notes, and snippets.

@dcolish
Created September 5, 2012 15:00
Show Gist options
  • Select an option

  • Save dcolish/3637915 to your computer and use it in GitHub Desktop.

Select an option

Save dcolish/3637915 to your computer and use it in GitHub Desktop.
import java.util.*;
class ItorTest {
ArrayList<String> foo;
public static void main (String [] args) {
ArrayList<String> foo = new ArrayList<String>();
foo.add("Hello");
foo.add("World");
for (Iterator<String> it = foo.iterator(); it.hasNext();) {
System.out.println(next(it));
}
}
public static String next(Iterator<String> bar) throws NoSuchElementException {
if (bar.hasNext()) {
return bar.next();
} else {
throw new NoSuchElementException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment