벡터(Vector) 사용 예(1)




import java.util.Vector;


public class VectorTest {

public static void main(String[] args) {

Vector vector = new Vector();

System.out.println("생성직후의 size : " + vector.size());


//1. vector객체에 데이터4개 삽입

vector.addElement(new String("망아지"));

vector.addElement(new String("송아지"));

vector.addElement(new String("강아지"));

vector.addElement(new String("병아리"));

System.out.println("데이터 삽입후의 size : " + vector.size());


//2. vector의 요소 가져오기

for(int i=0; i< vector.size(); i++){

String temp = (String)vector.elementAt(i);

System.out.println("vector" + i + "번째 :" + temp);

}

}

}

+ Recent posts