ArrayList 及其源码解析

1、数组介绍

因为数组在存储数据时是按顺序存储的,存储的内存也是连续的,所以其特点是读取数据比较容易
,插入删除比较困难

2.arraylist源码分析
  1)构造方法(默认容量为10)

  2)插入数据
  扩容操作 newCapacity = oldCapacity +oldCapacity >>1

  3) 删除操作

  4)遍历操作
  arraylist在进行遍历操作时 删除元素会报错
  for(Integer num:list){
    if(num==12)
    list.remove();
  }

  只能通过迭代器来删除
  Iterator<Integer> it =list.iterator();
  while(it.hasNext()){
    Integer num=it.next();
    if(num==12){
      it.remove();
    }
  }

猜你喜欢

转载自www.cnblogs.com/houchen/p/11665470.html
今日推荐