关于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

posted @ 2017-07-10 19:00  Johnson_wang  阅读(19899)  评论(8编辑  收藏  举报