Skip to content

Instantly share code, notes, and snippets.

@a-r-d
Created November 20, 2016 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-r-d/a60f2bd9ea61e07018249b639d51e266 to your computer and use it in GitHub Desktop.
Save a-r-d/a60f2bd9ea61e07018249b639d51e266 to your computer and use it in GitHub Desktop.
Just a quick java iterator example.
// assume some stuff like this exists
ArrayList<String> lines = ...
BufferedWriter writer = ...
// get your iterator instance.
Iterator<String> iterator = lines.iterator();
String write = null;
// iterate + check inside of the while loop condition test.
while (iterator.hasNext() && (write = iterator.next()) != null) {
writer.append(write);
writer.flush();
writer.newLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment