package com.chunzhi;
import java.util.HashMap;
import java.util.Hashtable;
/*
java.util.Hashtable<K,V>集合 implements Map<K,V>接口
Hashtable:底層也是一個哈希表,線程安全的集合,單線程集合,速度慢
HashMap:底層是一個哈希表,線程不安全的集合,多線程集合,速度快
HashMap集合(之前所學所有集合):可以儲存null值,null鍵
Hashtable集合,不能儲存null值,null鍵
Hashtable和Vector集合一樣,再JDK 1.2版本之后被更先進的集合(HashMap, ArrayList)取代了
Hashtable的子類Properties依然活躍在歷史舞台
Properties集合是一個唯一和IO流相結合的集合
*/
public class Test02Hashtable {
public static void main(String[] args) {
// HashMap集合(之前所學所有集合):可以儲存null值,null鍵
HashMap<String, String> map = new HashMap<>();
map.put(null, "a");
map.put("b", null);
map.put(null, null);
System.out.println(map); // {null=null, b=null}
// Hashtable集合,不能儲存null值,null鍵
Hashtable<String, String> table = new Hashtable<>();
table.put(null, "a"); // NullPointerException
table.put("b", null); // NullPointerException
table.put(null, null); // NullPointerException
System.out.println(table);
}
}