2013년 6월 28일 금요일

(130628) 5일차 HashTableTest2.java (Enumeration을 이용한 Map의 Hashtable 테스트)

 - Interface Enumeration<E>
 : hasMoreElements()
 : nextElement()
 : For example, to print all elements of a Vector<E> v:
   for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
       System.out.println(e.nextElement());


 - 소스
import java.util.Enumeration;
import java.util.Hashtable;

public class HashTableTest2 {

public static void main(String[] args) {
// map 계열인 Hashtable 선언
// Hashtable<Integer, String> hash = new Hashtable<>();
Hashtable<String, String> hash = new Hashtable<>();

// 데이터를 입력
hash.put("가", "유재석");
hash.put("나", "박명수");
hash.put("다", "정준하");
hash.put("라", "정형돈");
hash.put("마", "노홍철");
hash.put("바", "하하");
hash.put("사", "길");

Enumeration<String> e = hash.elements();
for( ; e.hasMoreElements() ; )
System.out.println(e.nextElement()); // 메모리에서 하나를 가져오고 없애버림 (순서가 없음, 무엇을 가져올지 모름) // 남아있는게 있으면 true를 리턴해서 계속 보내줌
}
}


 - 결과