Runtime:
package com.codeurjava.hashtable;
import java.util.*;
public class hashtable_replace_key {
public static void main(String args[]) {
// eine Hashtabelle erstellen
Hashtable ht = new Hashtable();
// peers
einfügen ht.put(1, "A");
ht.put(2, "B");
ht.put(3, "C");
System.out.println("Hashtabelle vorher: "+ht);
//Schlüssel zum Ändern
int-Schlüssel = 2;
// bevor wir den Wert des gesuchten Schlüssels abrufen müssen
// und diesen Wert in einer Variablen speichern
// so dass wir dem neuen Schlüssel
String val = (String) ht.get(2);
// Lösche den altenht.remove(key);
// Einfügen des neuen Schlüssel-Wert-Paares
ht.put(22,val);
System.out.println("Hashtabelle nach: "+ht);
}
}
Hashtable before: {3=C, 2=B, 1=A}
Hashtable nach: {3=C, 1=A, 22=B}
Please disable your ad blocker and refresh the window to use this website.