For each Construct in Java:
Java 1.5 introduces a new way of iterating over a collection of objects. The foreach loop is also known as the enhanced for loop. It is a new syntactical construct designed to simplify iteration. The foreach loop should make iteration more consistent, but only if and when everyone starts using it.
Effective use of the foreach loop depends on using Java 1.5's parameterized types, also known as generics. You can refer to generics section in this blog.
String[] moreNames = { "d", "e", "f" };
for (String name: moreNames)
System.out.println(name.charAt(0));

0 Comments:
Post a Comment
<< Home