Saturday, November 17, 2007

Spot the mistake

Can you spot the mistake in this code?

// BROKEN - throws NoSuchElementException!

for (Iterator i = suits.iterator(); i.hasNext(); )
for (Iterator j = ranks.iterator(); j.hasNext(); )
sortedDeck.add(new Card(,;

If not, check this article on the Java for...each loop. 

Note: This text was originally posted on my earlier blog at

No comments: