栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Map 接口实现类-Hashtable

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Map 接口实现类-Hashtable

Map 接口实现类-Hashtable
  • 14.1 HashTable 的基本介绍
  • 14.2 Hashtable 和 HashMap 对比

14.1 HashTable 的基本介绍

HashTableExercise.java

package com.xjz.map_;

import java.util.Hashtable;

@SuppressWarnings({"all"})
public class HashTableExercise {
    public static void main(String[] args) {
        Hashtable table = new Hashtable();
        table.put("john",100);//ok
        //table.put(null,100);//异常 NullPointerException
        //table.put("john",null);//异常 NullPointerException
        table.put("lucy",100);//ok
        table.put("lic",100);//ok
        table.put("lic",88);//替换
        table.put("hello1",1);
        table.put("hello2",1);
        table.put("hello3",1);
        table.put("hello4",1);
        table.put("hello5",1);
        table.put("hello6",1);

        System.out.println(table);

        //简单说明一下 Hashtable 的底层
        //1. 底层有数组 Hashtable$Entry[11]  初始化大小为 11
        //2. 临界值 threshold 8 = 11 * 0.75
        //3. 扩容:按照自己的扩容机制来进行即可。
        //4. 执行 方法 addEntry(hash, key, value, index); 添加k-v 封装到Entry
        //5. 当 if(count >= threshold) 满足时,就进行扩容
        //6. 按照 int newCapacity = (oldCapacity << 1) +1 ;  的大小扩容。
    }
}
14.2 Hashtable 和 HashMap 对比

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1023491.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号