新入公司,閱讀代碼的時候發現了一行代碼,為
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 加載因子 在下文有描述