这是我在学习Java集合框架时对 ArrayList 的源码级解析,我将许多常用的方法都做出了解释,还有许多更为底层的地方没有涉及到,等到以后有机会我再补全。如果这篇文章对您有帮助的话,希望能给作者一个赞哦!!!
文章目录
- 类图
- 1. ArrayList 的属性
- 2. 构造方法
- 2.1 public ArrayList(int initialCapacity)
- 2.2 public ArrayList()
- 2.3 public ArrayList(Collection<? extends E> c)
- 3. 添加方法 add()
- 3.1 public boolean add(E e)
- 3.2 add(int index, E element)
- 4. 移除方法 remove()
- 4.1 public E remove(int index)
- 4.2 public boolean remove(Object o)
- 4.3 private void fastRemove(int index)
- 5. 查找方法 get()
- 5.1 public E get(int index)
- 5.2 public int indexOf(Object o)
- 6. set() 方法
- 7. 序列化方法 writeObject()
- 8. 反序列化方法 readObject()
- 9. subList() 方法
- 10. 迭代器实现
- 11. 总结
cs