【Java分析】LinkedList分析

it2022-05-11  71

目录:

一:java集合框架

二:ArrayList

三:LinkedList

四:HashMap

 

 

一:总结

1、底层数据结构:双向链表,有头尾指针。

2、实现接口:RandomAccess 随机访问 get(index)

                       Cloneable : 可以克隆 标记接口

                        Serializable: 序列化 标记接口

                        *Deque: 队列 可以先进先出(如果要当做队列用才具有)

                                              List list = new LinkedList();//就是链表 没有先入先出

                                              Queue queue = new LinkedList();//队列 先入先出

3、继承AbstractSequentialList抽象类:在遍历LinkedList的时候,最好用迭代器。因为链表时间复杂度是O(index)

4、线程不安全

 

二:分析

定义:

         只要搞清楚了双向链表的操作就会LinkedList的操作了

          Deque接口表示是一个双端队列,那么也意味着LinkedList是双端队列的一种实现,所以,基于双端队列的操作在LinkedList中全部有效。

public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, java.io.Serializable { 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;

内部类:

private static class Node<E> { E item; Node<E> next; Node<E> prev; Node(Node<E> prev, E element, Node<E> next) { this.item = element; this.next = next; this.prev = prev; } }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


最新回复(0)