Runtime:
package com.codeurjava.hashtable;
import java.util.*;
public class hashtable_replace_key {
public static void main(String args[]) {
// 해시 테이블 생성
해시 테이블 ht = new Hashtable();
// 피어 삽입
ht.put(1, "A");
ht.put(2, "B");
ht.put(3, "C");
System.out.println("이전 해시 테이블: "+ht);
//변경할 키
int key = 2;
// 찾고자 하는 키의 값을 검색하기 전에
// 이 값을 변수에 저장합니다
// 새 키에 할당합니다
String val = (String) ht.get(2);
// 이전
ht.remove(key);
// 새 키-값 쌍 삽입
ht.put(22,val);
System.out.println("이후 해시 테이블: "+ht);
}
}
Hashtable 이전: {3=C, 2=B, 1=A}
Hashtable 이후: {3=C, 1=A, 22=B}
Please disable your ad blocker and refresh the window to use this website.