目录
ArrayList 常用方法 源码解析
0.构造器
1.toArray
2.Set
3.indexof
4.get
5.remove
6.add
7.forEach
8.size
ArrayList 常用方法 源码解析
0.构造器

说明:当传递的参数为集合类型时,会把集合类型转化为数组类型,并赋值给elementData。
1.toArray
集合类型转化为数组类型。
2.Set
public Object set(int i, Object obj)
{
rangeCheck(i); // 检验索引是否合法
checkForComodification(); // 旧值
Object obj1 = elementData(offset + i); // 赋新值
elementData[offset + i] = obj; // 返回旧值
return obj1;
}
3.indexof
4.get
5.remove
6.add
插入时