Skip to content

Instantly share code, notes, and snippets.

@dbellettini
Created February 9, 2012 11:26
Show Gist options
  • Save dbellettini/1779408 to your computer and use it in GitHub Desktop.
Save dbellettini/1779408 to your computer and use it in GitHub Desktop.
weird foreach
Set<Author> authorsSet = new HashSet<Author>();
try {
for(int i=0; ; i++) {
// checking if author already exists in the DB
Author author = authorDAO.findAuthorByName(authors[i]);
if (author == null) {
author = new Author();
author.setName(authors[i]);
}
authorsSet.add(author);
}
} catch(ArrayIndexOutOfBoundsException e) {
// ignore; this just means that i has reached the end of the array
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment