特点
- 存放的元素是键值对:k-v
- Hashtable的key和value都不能为空
- Hashtable使用方法基本上和HashMap一样
- Hashtable是线程安全的,HashMap是线程不安全的
结构
- 底层有数组Hashtable$Entry[ ],初始化大小为11
- 临界值threshold 8 = 11 * 0.75
扩容方式
当if (count >= threshold) 满足时,按照 int newCapacity = (oldCapacity << 1) + 1; 进行扩容
package aggregate.map;
import java.util.Hashtable;
public class HashTable_ {
public static void main(String[] args) {
//key和value值都不能为null,否则报异常
Hashtable hashtable = new Hashtable();
hashtable.put("001","zhangwei");
hashtable.put("002","zhangwei");
hashtable.put("003","zhangwei");
//hashtable.put("004",null);
//hashtable.put(null,"zhangwei");
hashtable.put("006","zhangwei");
hashtable.put("007","zhangwei");
hashtable.put("008","zhangwei");
hashtable.put("009","zhangwei");
hashtable.put("0010","zhangwei");
hashtable.put("0011","zhangwei");
//1.底层数组Hashtable$Entry初始化大小为11
//2.临界值threshold 8 = 11*0.75
//3.当if (count >= threshold) 满足时,按照 int newCapacity = (oldCapacity << 1) + 1; 进行扩容
//4.通过 addEntry(hash, key, value, index); 将值添加到Entry中
System.out.println(hashtable);
}
}