Hashtable底层

package com.collection_.map_;

import java.util.Hashtable;

@SuppressWarnings({"all"})
public class HashTableExercise {
    public static void main(String[] args) {
        /*
        Map接口实现类-Hashtable
            1. 存放的元素时键值对:即K-V
            2. hashtable的键和值都不能null,否则会抛出NullPointerException(空值异常)
            3. hashtable 是线程安全的(synchronized),hashMap是线程不安全的


        Hashtable底层
            1. 底层有数组Hashtable$Entry[] 初始化大小为11
            2. 临界值 threshold 8 = 11*0.75
            3. 扩容:按照自己的扩容机制来扩容(newCapacity = (oldCapcity << 1) + 1)
         */

        Hashtable table = new Hashtable();
        table.put("hello1",100);//ok
        table.put("hello2",100);//ok
        table.put("hello1",80);//替换
        //table.put(null,100);//异常
        //table.put("hello1",null);//异常
        System.out.println(table);

    }
}


版权声明:本文为l1341886243原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。