package ch09;
import java.util.*;
public class Ch0908
{
public static void main(String[] args)
{
//HashMap은 HashTable과 사용메서드 및 개념이 유사하지만,
//보통 다중사용자환경을 고려하는 JSP환경에서 안정적.
//데스크톱 어플리케이션 개발에서는 HashTable이 많이 사용된다.
HashMap ht = new HashMap();
ht.put("영화","화산고"); //-> ht.get("영화");
ht.put("게임","부르드워");
ht.put("소설","이순신");
Iterator iter = ht.keySet().iterator();
while(iter.hasNext())
{
String key = (String)iter.next();
String value = (String)ht.get(key);
System.out.println("Key : "+key);
System.out.println("Value : "+value);
}
}
}
****** Ch0909.java ******
package ch09;
import java.util.*;
public class Ch0909
{
public static void main(String[] args)
{
/* Map은 인터페이스이지 클래스가 아니다...
* 따라서 직접개체생성은 할 수 없으며
* Map인터페이스를 상속받은 하위클래스인
* Hashtable,HashMap클래스의 개체를
* 대입하여 초기화할 수 있다...
*/
Hashtable ht=new Hashtable();
Map map=ht;
/*
HashMap hmap=new HashMap();
map=hmap;
*/
//고로 put메서드는 Map인터페이스의 추상메서드이며
//Hashtable,HashMap에서 클래스에 맞게 구현된
//추상메서드의 구현임을 알 수 있다...
//map.put(arg0, arg1)
}
}