Code example for Hashtable

Methods: containsKey, get, remove

0
package odpsystem.sys; 
 
import java.util.Hashtable; 
 
public class DoubleHashtable { 
 
    private Hashtable table = new Hashtable();
 
    public Hashtable getSubTable(String key) {
        if (table.containsKey(key)) {
            return (Hashtable) table.get(key);
        } 
        Hashtable subTable = new Hashtable();
        table.put(key, subTable);
        return subTable;
    } 
 
    public void put(String key, String subKey, Object value) {
        Hashtable subTable = getSubTable(key);
        subTable.put(subKey, value);
    } 
 
    public boolean containsKey(String key, String subKey) {
        if (!table.containsKey(key)) {
            return false; 
        } 
        return getSubTable(key).containsKey(subKey);
    } 
 
    public Object get(String key, String subKey) {
        return getSubTable(key).get(subKey);
    } 
 
    public boolean isEmpty() { 
        return table.isEmpty();
    } 
 
    public void delete(String key, String subKey) {
        getSubTable(key).remove(subKey);
    } 
}