zoukankan      html  css  js  c++  java
  • ArrayList

    这里介绍一些 ArrayList 常用的代码,都是望名生义,不再举例。

    获取元素值

    object value = al[index]; //al 为 ArrayList 对象,一般需要再对 value 进行类型转换,比如:int n = (int)value;

    设置元素值

    al[index] = value; //al 为 ArrayList 对象,index 必须小于 Count

    追加元素

    int ArrayList.Add(object value) 返回添加的元素的索引

    插入元素

    void ArrayList.Insert(int index, object value)

    删除元素

    删除元素后,后面的元素会前移,但 Capacity 不会变化。

    void ArrayList.Remove(object obj) 从前(索引 0)往后查找,删除找到的第一个和 obj 相同的元素
    void ArrayList.RemoveAt(int index) 删除索引 index 对应的元素
    void ArrayList.RemoveRange(int index, int count) 从索引 index 开始,删除 count 个元素

    查找元素

    int ArrayList.IndexOf(object value) 从前(索引 0)往后查找,返回找到的第一个和 obj 相同的元素的索引
    int ArrayList.IndexOf(object value, int startIndex)
    int ArrayList.IndexOf(object value, int startIndex, int count)
    int ArrayList.LastIndexOf(object value) 从后往前(索引 0)查找,返回找到的第一个和 obj 相同的元素的索引
    int ArrayList.LastIndexOf(object value, int startIndex)
    int ArrayList.LastIndexOf(object value, int startIndex, int count)
  • 相关阅读:
    取模 分数取模 快速幂 费马小定理
    “科林明伦杯”哈尔滨理工大学第十届程序设计竞赛 部份签到题
    shell 脚本
    pyhcl语法
    数据库实验1 SQL
    杂七杂八 Ubuntu Linux
    Kattis, Kattis 的一些问题题解
    Meow Factor 【暴力】
    解决 Eclipse 项目有红感叹号的方法
    RuntimeException与CheckedException
  • 原文地址:https://www.cnblogs.com/henyihanwobushi/p/2640223.html
Copyright © 2011-2022 走看看