HashMap底层

Day18

HashMap底层

场景:

HashMap<Student, String> map = new HashMap<>();
		
map.put(null, "赏花");//null
map.put(null, "抚琴");//赏花
map.put(new Student("宇", '男', 23, "2402", "001"), "踢足球");//null
map.put(new Student("蒲", '男', 21, "2402", "002"), "看电影");//null
map.put(new Student("小康", '男', 22, "2402", "003"), "看抖音");//null
map.put(new Student("小康", '男', 22, "2402", "003"), "写代码");//看抖音

源码:

public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>{
    
    
	
   //默认初始化容量(必须是的2幂) - 16
   static final int DEFAULT_INITIAL_CAPACITY = 1 << 4;
   //最大容量
   static final int MAXIMUM_CAPACITY = 1 << 30;
   //默认的负载因子
   static final float DEFAULT_LOAD_FACTOR = 0.75f;
   //空内容的数组
   static final Entry<?,?>[] EMPTY_TABLE = {
    
    };
   
   //hash数组/hash表 - new Entry[16];
   transient Entry<K,V>[] table = (Entry<K,V>[]) EMPTY_TABLE;
   //元素个数
   transient int size;//0
   //阈值
   int threshold;//12
   //负载因子
   final float loadFactor;//0.75f
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值