HashMap(一):默认参数和属性

本文详细探讨了HashMap的默认参数,包括DEFAULT_INITIAL_CAPACITY(16)、MAXIMUM_CAPACITY(2^30)、DEFAULT_LOAD_FACTOR(0.75f)。HashMap在元素达到TREEIFY_THRESHOLD(8)时可能转为红黑树,当元素数量减小到UNTREEIFY_THRESHOLD(6)时,会将红黑树转换回链表。此外,MIN_TREEIFY_CAPACITY(64)规定了何时避免树化。文章还介绍了HashMap的关键属性如table、entrySet、size、modCount、threshold和loadFactor,并提出了关于加载因子精度与扩容条件的思考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、默认参数源码

    /**
     * The default initial capacity - MUST be a power of two.
     */
    static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

    /**
     * The maximum capacity, used if a higher value is implicitly specified
     * by either of the constructors with arguments.
     * MUST be a power of two <= 1<<30.
     */
    static final int MAXIMUM_CAPACITY = 1 << 30;

    /**
     * The load factor used when none specified in constructor.
     */
    static final float DEFAULT_LOAD_FACTOR = 0.75f;

    /**
     * The bin count threshold for using a tree rather than list for a
     * bin.  Bins are co
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值