Tuesday, June 21

"for each or enhanced for statement" : Java

The Enhanced For Loop (since Java 5)

The enhanced for loop allows you to iterate through a collection without having to create an Iterator or without having to calculate beginning and end conditions for a counter variable.

for example:
for (char c : hashMap.keySet())
{
}

means, for each character in the Set (of characters).

Anything that implements Iterable can be supported.
This is particularly nice in Collections.

No comments:

Post a Comment