Possible Duplicate:
foreach loop a java creation?
I am learning a Java program. But something , I don’t understand. It is following:
for(Some obj : vc) {
System.out.println(obj.getResult());
I tried to search “for-loop” in my book and google. They just had some basic method.
What means about “for(Some obj : vc)”?
Thanks a lot!
It’s a for-each loop, introduced in Java 1.5.
You can read it as “For each
Someinvc“.It’s effectively the same as using an iterator like so:
Only with less bloat.
Also, note that this syntax isn’t limited to things that are
Iterable. This would also work ifvcwere an array ofSome(i.e.Some[]).