You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** *如有必要,增加此ArrayList实例的容量,以确保它至少可以容纳由minimum capacity参数指定的元素数。 * * @param minCapacity所需的最小容量(也就是minimum capacity) */publicvoidensureCapacity(intminCapacity) {
intminExpand = (elementData != DEFAULTCAPACITY_EMPTY_ELEMENTDATA)
// any size if not default element table
? 0// larger than default for default empty table. It's already// supposed to be at default size.
: DEFAULT_CAPACITY;
if (minCapacity > minExpand) {
ensureExplicitCapacity(minCapacity);
}
}
对于ArrayList添加大量元素,最好调用ensureCapacity方法进行提前扩容,为啥不直接用有参构造方法呢,这个方法存在的意义在哪呢?
The text was updated successfully, but these errors were encountered: