본문 바로가기

프로그래밍/Java

자바/Java 가중 for문 에서 일반 for문 처럼 index 사용하기

Source

 

package exam;

 

import java.util.ArrayList;

 

public class Exam01 {
 
 public static void main(String[] args){
  
  ArrayList<String> list = new ArrayList<String>();
  
  list.add("_id");
  list.add("name");
  list.add("contact");
  list.add("email");
  
  
  int i = 0;
  
  for(String s : list) {
   System.out.println("Test getColumnNames["+ i++ + "] = " + s);
  }
  
 }

 

 

결과

 

Test getColumnNames[0] = _id
Test getColumnNames[1] = name
Test getColumnNames[2] = contact
Test getColumnNames[3] = email