Java_List常见方法

来源:互联网 发布:苏氏钻头淘宝 编辑:程序博客网 时间:2024/05/22 06:42
List:有序(存入和取出的顺序一致),元素都有索引(角标),元素可以重复。
常见方法:
    有一个共性特点就是可以操作角标
1、添加
    void add(int index,E element);
    void add(int index,Collection c);
2、删除
    Object remove(int index);//返回被删除对象
3、修改
    Object set(int index,E element);//返回被替换对象
4、获取
    Object get(int index);
    int indexOf(Object obj);
    int LastIndex(Object obj);
    List subLiat(int fromIndex,int toIndex);//包含头不包含尾
List集合可以对元素完成增删改查

List子类对象
Vector:内部是数组数据结构,是同步的。
ArrayList:内部是数组数据结构,是不同步的,替代了Vector。查询块
LinkedList:内部是链表数据结构,是不同步的。增删块

LinkList
    addFirst();
    addList();
    jdk1.6
        offerFirst();
        offerLast();
    
    getFirst();//获取但不移除,如果链表为空抛出NoSuchElementException
    getList();
    jdk1.6:
        peekFirst();//获取但不移除,如果链表为空返回null
        peekLast();
    
    removeFirst();//获取并移除,如果链表为空抛出NoSuchElementException
    removeLast();
    jdk1.6
        pollFirst();//获取并移除,如果链表为空返回null
        polllast();