728x90

Java SE 5.0 에 추가된 컬렉션을 위한 반복문

< 형식 >
   for(자료형  변수명 : Collection자료)
{
            처리문;
}
기존방법

public  void  oldFor ( Clollection c )
{
     for( Iterator  i = c.iterator() : i.hasNext() ;)
         {
               String str = (String)i.next();
               sb.append(str);
          }
}

새로운 방법

public void newFor( Collection<String>c)
{
    for(String str:c)
       {  
            sb.append(str);
        }
}
class ForTest
{
 public static void main( String [] args )
 {
  String [] arr = new String[]{"소녀시대","카라","원더걸스"};
  for(String a:arr)
  {
   System.out.println(a);
  }
  System.out.println();
  
 }// end main
}

+ Recent posts