'Hashtable'에 해당되는 글 1건

  1. 2009.02.01 Map(HashTable)사용 예제 소스
Java2009. 2. 1. 15:22

public class TestClient {

 public static void main(String[] args) {
  // Map 선언 <key, Value>
  Map map = new Hashtable<Integer, Object>();
  
  //hashtable에 key와 value넣기
  map.put(1, "숫자일");
  map.put(2, "숫자이");
  map.put(3, "숫자삼");
  map.put(4, "숫자사");
  //hashtable의 value꺼내오기
  System.out.println(map.get(2));
  //hashtable에 key와 value지우기
  map.remove(2);
  System.out.println(map.get(2));
  // 지운부분에 다시key와 value넣기
  map.put(2, "숫자이");
  System.out.println(map.get(2));
  // 중복된 키값에 value넣을경우 최신으로 넣은게 들어간다
  map.put(2, "중복이");
  System.out.println(map.get(2));
  
 }
}

Posted by 위푸