关于new HashMap<>(1)中1的理解(hashMap的初始容量)


新入公司,阅读代码的时候发现了一行代码,为

   

Map<String, String> map=new HashMap<>(1);

对于这个括号里面的1不能理解,于是查了资料,大概了解了。

解释如下:这个1被称为初始容量。

API:

/**
     * Constructs an empty <tt>HashMap</tt> with the specified initial
     * capacity and the default load factor (0.75).
     *
     * @param  initialCapacity the initial capacity.
     * @throws IllegalArgumentException if the initial capacity is negative.
     */
    public HashMap(int initialCapacity) {
        this(initialCapacity, DEFAULT_LOAD_FACTOR);
    }

 

关于 DEFAULT_LOAD_FACTOR 加载因子 在下文有描述

文章后续加入补充:https://www.cnblogs.com/wangzun/p/13087540.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM