View RSS Feed

My Java Tips

  1. Enhanced for-loop (Java 5.0)

    by , 11-20-2011 at 06:14 PM (My Java Tips)
    Java 5.0 introduced an enhanced for-loop. In this post, I'll write about it.

    The enhanced for loop provides a simple structure allows one to simplify code by presenting for-loops that visit each element of an array/collection without explicitly expressing how one goes from element to element.

    The new for loop makes programming simpler. For example, if you want to print each element for an array, you used to do that with a for loop in the following way:

    Java SE