Collection之List方法和分类

来源:互联网 发布:矩阵相加 编辑:程序博客网 时间:2024/05/21 07:00
List:特有的常见方法:
   其他常见方法见本博客中的 Collection大家族文章
1,添加
    void add(index,element);
    void addAll(index,collection);


2,删除;
    Object remove(index):


3,修改:
    Object set(index,element);
    

4,获取:
    Object get(index);
    int indexOf(object);
    int lastIndexOf(object);

    List subList(from,to);

5.特有方法:

ListIterator lit = List.listIterator();可以在迭代过程中对集合元素进行操作:

while(lit.hasNext()){Object obj = lit.next();if(obj.equals("abc2")){    lit.set("abc9");//lit.add("abc9"); }   }


   
List的分类:
    |--Vector:内部是数组数据结构,是同步的。增删,查询都很慢!
    |--ArrayList:内部是数组数据结构,是不同步的。替代了Vector。查询的速度快。
    |--LinkedList:内部是链表数据结构,是不同步的。增删元素的速度很快。
0 0
原创粉丝点击