Monday, February 7, 2011

For each in Java

package mypackage;


import java.util.*;

public class FirstIterator {

      public static void main(String[] args) {
            ArrayList<String> a = new ArrayList<String>();
            String abc = "hi";
            String abc1="hello";
           
            a.add(abc);
            a.add(abc1);
      try
            for( String anew : a )
            {
                  System.out.println(anew);
            }
      }
      catch (Exception e)
      {
            System.out.println("Done");
      }
      }

}

No comments:

Post a Comment