【IT168 技术文档】在仔细分析源代码之前,我们来看看Hashtable提供的一些接口方法。
public int size();
public boolean isEmpty() ;
public synchronized Enumeration keys();
public synchronized Enumeration elements();
public synchronized boolean contains(Object value) ;
public synchronized boolean containsKey(Object key);
public synchronized Object get(Object key);
public synchronized Object put(Object key, Object value) ;
public synchronized Object remove(Object key);
public synchronized void clear() ;
public synchronized void clear() ;
public boolean isEmpty() ;
public synchronized Enumeration keys();
public synchronized Enumeration elements();
public synchronized boolean contains(Object value) ;
public synchronized boolean containsKey(Object key);
public synchronized Object get(Object key);
public synchronized Object put(Object key, Object value) ;
public synchronized Object remove(Object key);
public synchronized void clear() ;
public synchronized void clear() ;
上面的方法我就不一一介绍了,具体的用法也是很简单,相对大家对此也比较熟悉了。
Hashtable的用法
Hashtable 有2个构造函数
public Hashtable(int initialCapacity); //指定容量大小
public Hashtable() {
this(11); //默认的容量是11,为什么是11,而不是10呢?
}
public Hashtable() {
this(11); //默认的容量是11,为什么是11,而不是10呢?
}
Demo1
Hashtable sTable = new Hashtable();
sTable.put("wuhua","wuhua");
sTable.remove("wuhua");
sTable.clear();
sTable.put("wuhua","wuhua");
sTable.remove("wuhua");
sTable.clear();
上面是简单的用法。