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);

          

  • 相关阅读:
    浏览器开发者工具----F12 功能介绍
    python 爬虫之beautifulsoup(bs4)使用 --待完善
    python 爬虫之beautifulsoup(bs4)环境准备
    python dic字典使用
    python list的使用
    python 实现进制转换(二进制转十进制)
    字符串str的使用方法
    python 第一课 helloworld
    python 学习地址
    React中setState 什么时候是同步的,什么时候是异步的?
  • 原文地址:https://www.cnblogs.com/2nao/p/6436082.html
Copyright © 2011-2022 走看看