- The for-each loop can handle only one iteration variable.
- Nested iterations are allowed.
- Iterating over varargs. Java 5.0 now allows a variable number of arguments of a single type to be passed in as the last parameter to a method. The compiler collects these varargs parameters into an array of that type. The for-each loop can be used to iterated over the varargs.
- Do not modify the list during iteration
- When appropriate, implement java.util.RandomAccess to allow for compiler optimizations
- Consider returning an Iterable rather than a List
- Consider returning Iterable views rather than implementing Iterable
- Return zero length arrays or empty lists rather than nulls
Tuesday, November 07, 2006
The Java 5 for each loop
A new article on java.net, Nuances of Java 5.0 for-each loop, discusses the Java 5 for-each loop, in great detail. The article covers common programming errors when using the for-each loop, how the enhanced for-loop compares with the equivalent implementation with the regular for-loop, how to write new classes that can be used as targets of a for-each loop compiler optimizations of the for-each loop, and a lot more. Here is a list of the talking points:
Labels:
example/sample code,
tips
Subscribe to:
Post Comments (Atom)
Popular Posts
-
IBM has released a free version of DB2 named DB2 express-C. It is free for development, deployment, and redistribution. It is supported on t...
-
The strategy pattern is intended to provide a means to define a family of algorithms, encapsulate each one as an object, and make them inte...
-
The previous post described how to implement a JMS messaging client using Spring JMS . This post will describe how to implement the Message ...
-
In a previous post, I described how to use Quartz scheduler for scheduling . In this post, I describe the configuration changes required for...
-
Displaytag is an opensource tag library that can be used to display tables on JSPs. Apart from being able to display tables, the displaytag...
-
JAD Eclipse is an eclipse plug-in for the JAD Decompiler . The following is a quick description of how to setup JAD Eclipse (assuming you a...
-
If you happen to forget WebSphere administrative console password , or are locked out due to user registry problems etc and cannot login to ...
-
Web applications that do not use SSL to protect all their resources run faster than the ones that do. However, passing sensitive information...
-
This post will describe how to create and deploy a Java Web Application war to Heroku using Heroku CLI. You will need a basic understanding ...
-
New posts with iText 5.5.12 Following are two new posts for PDF Merge with iText 5.5.12 Merge PDF files using iText 5 Merge and Paginate PDF...
very nice of u that u have summarized all key-points of for-each loop in java so easily hat it makes easy to understand and view it as categoriesed....hank u very much....
ReplyDelete