zoukankan      html  css  js  c++  java
  • ArrayList深入学习

    ArrayList:

         a. 默认初始容量为10的Object[]类型动态数组,当容量不足时,新容量=原来的容量*3/2+1.重新生成一个数组,将原来的数组复制到新的数组中

         b. 继承自AbstractList,实现了List接口,

         c. 实现了RandmoAccess接口,提供随机访问功能

         d. 实现了Serializable接口,支持序列化

         e. 是线程不安全的,在单线程中使用

    ArrayList的三种遍历方式:

          1.通过迭代器遍历

            Iterator it=list.iterator();

            while(it.hashNext){

              it.next();

            }

            访问效率最低

           2.随机访问,通过索引值遍历

            for(int i=0;i<list.size();i++){

              list.get(i);    

            }

            访问效率最高

            3.增强for

            for(int i:list){

              i;

            }

            位于两者之间

          可以通过下面的方法将集合变为数组

         Integer[] newText = (Integer[])list.toArray(new Integer[list.size]);

    ArrayList中的常用方法

        boolean  add(E object);

        boolean contains(Object object);

        int size();

        E get(int index);

        E remove(int location );

        E set(int location,E obj);

          

  • 相关阅读:
    Golang 爬虫02
    Golang使用正则
    gin框架对接快递100 查询快递跟踪记录 Golang实现快递查询
    Jetbrains系列产品2019.3.4最新激活方法[持续更新]
    Linux下安装Fiddler
    Golang 爬虫01
    Github进行fork后如何与原仓库同步
    Pr 的导出视频
    Linux-平均负载指数
    Linux-进程管理命令
  • 原文地址:https://www.cnblogs.com/2nao/p/6436082.html
Copyright © 2011-2022 走看看