프로그래밍 정리/자바

Enumeration / Iterator 소스

주누다 2013. 5. 31. 04:38
반응형

import java.util.Enumeration;

import java.util.Hashtable;

import java.util.Iterator;

import java.util.Vector;



public class EnumTest {

public static void main(String[] args) {

Vector vector = new Vector();

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

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

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

Hashtable hashtable = new Hashtable();

hashtable.put("1", new String("홍길동"));

hashtable.put("2", "안녕하세요");

hashtable.put("4", new String("017-277-9999"));

Enumeration ei = hashtable.keys();

while(ei.hasMoreElements()){

String temp = (String)ei.nextElement();

System.out.println("hashtable의 Enumeration : " + temp);

}

System.out.println();

Iterator ih = hashtable.values().iterator();

while(ih.hasNext()){

String temp = (String)ih.next();

System.out.println("hashtable의 Iterator : " + temp);

}

}

}



======================================================================================


결과 :

hashtable의 Enumeration : 4

hashtable의 Enumeration : 2

hashtable의 Enumeration : 1


hashtable의 Iterator : 017-277-9999

hashtable의 Iterator : 안녕하세요

hashtable의 Iterator : 홍길동




반응형