• java基础集合类之ArrayList---01


    集合类之ArrayList

    ArrayList<E>:
    1.可调整大小的数组实现
    2.<E>:是一种特殊的数据类型,泛型
    3.在出现E的地方我们使用引用数据类型替换即可:ArrayList<String>
    

    ArrayList构造方法和添加方法

    方法名                                    说明
    public ArrayList()                    创建一个空的集合
    public boolean add(E e)          将指定的元素追加到此集合的末尾
    public void add(int index,E element)    在此集合中的指定位置插入指定的元素
    public boolean remove(Object o)        删除指定的元素,返回删除是否成功
    public E remove(int index)          删除指定索引处的元素,返回被删除的元素
    public E set(int index, E element)   修改指定索引处的元素,返回被修改的元素
    public E get(int index)               返回指定索引处的元素
    public E get(int index)               返回指定索引处的元素
    public int size()                        返回集合中的元素的个数
    
    import java.util.ArrayList;
    
    public class ArrayListDemo {
        public static void main(String[] args) {
            // 创建一个空集合
            ArrayList<String> arr= new ArrayList<>();
            // System.out.println(arr.add("hello"));  // 返回boolean类型
            arr.add("hello")
            arr.add("world")
            arr.add(1,"javase")
        }
    }
    
    

    -------------------------------------------

    个性签名:代码过万,键盘敲烂!!!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

  • 相关阅读:
    vnc安装
    centos下安装图形界面
    granfana telegraf influx安装与使用
    jenkins安装与使用
    yum使用手册
    Python模块--并发相关threading、multiprocessing、Queue、gevent
    Python模块--logging
    Python模块--psutil
    python模块--Beautifulsoup
    Python模块--Pexpect
  • 原文地址:https://www.cnblogs.com/weiweivip666/p/14599623.html
Copyright © 2020-2023  润新知