黑马程序员技术交流社区

标题: List集合 [打印本页]

作者: _let'sgo    时间: 2015-10-31 21:41
标题: List集合
------| List
---------| ArrayList  底层采用数组实现,默认10。 查询快,增删慢。
---------| LinkedList  底层采用链表实现

List集合特有方法:
1:增加
        void add(int index, E element) 指定位置添加元素            
        boolean addAll(int index, Collection c) 指定位置添加集合  
2:删除
E remove(int index) 删除指定位置元素

3:修改
                E set(int index, E element)    返回的是需要替换的集合中的元素
4:查找:
        E get(int index)             注意: IndexOutOfBoundsException
                int indexOf(Object o)         // 找不到返回-1
                lastIndexOf(Object o)
5:求子集合
                 List<E> subList(int fromIndex, int toIndex) // 不包含toIndex   

LinkedList特有方法:
1:方法介绍
            addFirst(E e)
addLast(E e)
getFirst()
getLast()
removeFirst()
removeLast()
如果集合中没有元素,获取或者删除元
素抛:NoSuchElementException
2:数据结构
                                1:栈 (1.6)
                                        先进后出
                                        push()
                                        pop()
                                2:队列(双端队列1.5)
                                        先进先出
                                        offer()
                                        poll()
3:返回逆序的迭代器对象      
descendingIterator()   返回逆序的迭代器对象





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2