JDK源码01

ArrayList

JDK版本:java11
fail-fast,快速失败机制,当对ArrayList进行迭代的时候,如果多个线程进行操作的时候,就会抛出ConcurrentModificationException
当前的操作次数与数组的操作次数进行比较,来判断是否有其他线程对当前对象进行修改
clear()和removeAll()
操作次数加1,设置size=0,将数组中保存的元素置空

Removes from this list all of its elements that are contained in the
specified collection.
public boolean removeAll(Collection<?> c) {
return batchRemove(c, false, 0, size);
}
移除列表中所有包含在指定集合中的元素

removeAll(Collection<?> c)中调用的的是批量删除的方法,即batchRemove(c, false, 0, size);
扩容

Returns a capacity at least as large as the given minimum capacity. Returns the current capacity increased by 50% if that suffices. Will not return a capacity greater than MAX_ARRAY_SIZE unless the given minimum capacity is greater than MAX_ARRAY_SIZE.返回至少和给定的最小容量一样大的存储大小,一般是1.5倍大小,不会返回容量大于最大值


添加


System.arraycopy(elementData, index, elementData, index+1, s-index)

Params:参数说明
src – the source array. 原数组(被复制的数组)
srcPos – starting position in the source array. 需要被复制元素的起始位置
dest – the destination array. 目标数组
destPos – starting position in the destination data. 复制元素添加的位置
length – the number of array elements to be copied. 复制元素的个数

addAll(Collection<? extends E> c)和addAll(int inedex,Collection<? extends E> c)与与上相同,只是将指定集合中的元素添加到数组中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值