zoukankan      html  css  js  c++  java
  • 2014/09/20 关于ArrayList的几种操作

    1.删除ArrayList集合元素

        删除ArrayList集合里面的元素时,提供了Clear方法,Remove方法,RmoveAt方法和RemoveRange方法。

    Clear方法是移除所有的元素

    Ref:int[] arr =new int[]{1,2,3,4,5,6};

            ArrayList List = new ArrayList(arr);

            List.Clear();

    2.Remove方法

        该方法用来从ArrayList中移除特定对象的第一个匹配项

    Ref:int arr =new int[]{1,2,3,4,5,6};

            ArrayList List = new ArrayList(arr);

           List.Remove(3);

    3.RemoveAt方法

    用来移除ArrayList指定索引的元素

    Ref:

    int arr =new int[]{1,2,3,4,5,6};

            ArrayList List = new ArrayList(arr);

           List.RemoveAt(3);

    4.RemoveRange方法

    该方法用来从ArrayList中移除一定范围的元素

    Ref:int[] arr = new int[]{1,2,3,4,5,6};

            ArrayList list = new ArrayList(arr);

            list.RemoveRange(3,2);

    查找ArrayList集合元素

    可以使用ArrayList类提供的Contain方法,IndexOf方法和LastIndexOf方法

    1.Contian方法

       用来确定某元素是否在ArrayList集合内。

    2.IndexOf方法

    返回整个ArrayList中第一个匹配项从零开始的索引。

    3.LastIndexOf方法

    返回整个ArrayList中最后一个匹配项从零开始的索引

  • 相关阅读:
    hdu 4015找规律
    hdu4473
    hdu 4016搜索
    hdu4465精度控制
    hdu 2965组合数学题
    hdu 4022map和list等数据结构的应用
    hdu4464超级大水题
    在ASP.NET中实现Url Rewriting
    DotText源码阅读(1)调试
    DotText源码阅读(2)数据库表结构
  • 原文地址:https://www.cnblogs.com/NongSi-Net/p/3983912.html
Copyright © 2011-2022 走看看