What is for-each style loop?

All collection classes implement the Iterable interface, which means that a collection can be cycled through by use of for-each style loop.
Example:
import java.util.*;
class demo
{
public static void main(String[] args){
ArrayList al=new ArrayList();
al.add("abcd");
al.add("kjhh");
al.add("kkhf");
al.add("cdfbg");
al.add("actfd");
int i=1;
for (String x:al)
{

System.out.print("The "+i+++" element is:");
System.out.println(x);}
}};

2 comments:


  1. Time is gold. We should treasure every second of it so that in time we will not regret anything because we only live ones.I have read your article and i was glad and inspired. Thanks for it, Cheers!
    Visit my site if you have time, Enjoy.

    n8fan.net

    www.n8fan.net

    ReplyDelete
  2. Great Resource and great site/engine.

    Gail
    www.imarksweb.org

    ReplyDelete