Programming puzzle — The enhanced for loop
If you don't know the Java 5.0 API and syntax, the following puzzle won't make sense to you. I pulled it out of an example that NkD and I were looking at and scratching our heads over. So here's the puzzle distilled to its purest form.
public static void main(String[] args) {
Set col = new HashSet();
col.add("Dagi");
col.add("NkD");
for (String key : col) {
col.remove(key);
System.out.println(key);
}
}
What's the output? Please include an explanation in the comments.
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio