import java.util.Enumeration;
import java.util.Hashtable;
public class removeAll_Hashtable {
public static void main(String[] s) {
Hashtable table = new Hashtable();
table.put("1", "val1");
table.put("2", "val2");
table.put("3", "val3");
Enumeration e = table.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
System.out.println(key + " : " + table.get(key));
table.remove(key);
}
System.out.println("After deletion");
System.out.println(table);
}
}
3: val3
2: val2
1: val1
After deletion
{}
import java.util.Hashtable;
public class removeAll_Hashtable {
public static void main(String[] s) {
Hashtable table = new Hashtable();
table.put("1", "val1");
table.put("2", "val2");
table.put("3", "val3");
table.clear();
System.out.println("After calling clear()");
System.out.println(table);
}
}
After calling clear()
{}
Please disable your ad blocker and refresh the window to use this website.