헤쉬테이블(HashTable) 사용 예(1)




import java.util.Hashtable;

public class HashtableTest {

public static void main(String[] args) {

Hashtable hashtable = new Hashtable();


//1. hashtable에 객체의 삽입 

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

hashtable.put("Age", new Integer(27));

hashtable.put("Tel", new String("02-1111-2222"));

hashtable.put("Handphone", new String("017-777-9999"));

hashtable.put("Etc", new String("I'm a boy"));


//키 값을 이용하여 객체 추출

String name = (String)hashtable.get("Name");

if (name != null) {

 System.out.println("Name = " + name);

}

 

Integer age = (Integer)hashtable.get("Age");

if (age != null) {

 System.out.println("Age = " + age.intValue());

}

}

}

+ Recent posts