Android之LinkList

2019-12-12  本文已影响0人  福later
public class LinkedList<E>
    extends AbstractSequentialList<E>
    implements List<E>, Deque<E>, Cloneable, java.io.Serializable
{
}

可以和ArrayList实现对比下Android之ArrayList
ArrayList 实现多了一个AccessRondom 接口,少了Deque 接口
LinkList 实现多了Deque接口,少了AccessRandom接口
想了解AccessRandom接口可以参看AccessRandom接口有啥用
Deque接口顾名思义,队列,说明LinkList 支持队列操作
来看看内部属性

transient int size = 0;

    /**
     * Pointer to first node.
     * Invariant: (first == null && last == null) ||
     *            (first.prev == null && first.item != null)
     */
    transient Node<E> first;

    /**
     * Pointer to last node.
     * Invariant: (first == null && last == null) ||
     *            (last.next == null && last.item != null)
     */
    transient Node<E> last;

    /**
     * Constructs an empty list.
     */
    public LinkedList() {
    }

    /**
     * Constructs a list containing the elements of the specified
     * collection, in the order they are returned by the collection's
     * iterator.
     *
     * @param  c the collection whose elements are to be placed into this list
     * @throws NullPointerException if the specified collection is null
     */
    public LinkedList(Collection<? extends E> c) {
        this();
        addAll(c);
    }

官方文档对LinkList 的解释是双向链表,那么很容易理解这里保留first ,last 指针的意义了,就是为了方便双向遍历和插入
本身添删改查没有太多要说,注意下按索引遍历,先是算下inde与size /2 比较下,然后决定是从头部开始遍历还是尾部开始遍历。

上一篇 下一篇

猜你喜欢

热点阅读