Java 5 For each syntax for arrays

You can use “for each” java syntax for iterating through the arrays, probably you are already aware you can definitely use for each syntax for iterating over classes implementing iterator.

here’s an example for iterating a array using for each syntax

public class test{

public static void main(String[]arg){

String []arr = new String[]{”one”,”two”};

for(String each: arr) System.out.println(each);
}

}

Output:

one
two

Written by Ravi Nallakukkala on March 25th, 2007 with no comments.
Read more articles on Java/ J2EE.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .