`

LinkedList

阅读更多
LinkedList


一、总结

1.基于 jdk 1.8 源码分析

2.

二、类声明

/**
 * Linked list implementation of the <tt>List</tt> interface.  Implements all
 * optional list operations, and permits all elements (including
 * <tt>null</tt>).  In addition to implementing the <tt>List</tt> interface,
 * the <tt>LinkedList</tt> class provides uniformly named methods to
 * <tt>get</tt>, <tt>remove</tt> and <tt>insert</tt> an element at the
 * beginning and end of the list.  These operations allow linked lists to be
 * used as a stack, {@linkplain Queue queue}, or {@linkplain Deque
 * double-ended queue}. <p>
 * 允许所有元素均为 null 
 *
 *
 * The class implements the <tt>Deque</tt> interface, providing
 * first-in-first-out queue operations for <tt>add</tt>,
 * <tt>poll</tt>, along with other stack and deque operations.<p>
 * 实现Deque接口,添加元素时如同 先进先出 的队列
 * 
 * All of the operations perform as could be expected for a doubly-linked
 * list.  Operations that index into the list will traverse the list from
 * the beginning or the end, whichever is closer to the specified index.<p>
 *
 * <p><strong>Note that this implementation is not synchronized.</strong>
 * If multiple threads access a linked list concurrently, and at least
 * one of the threads modifies the list structurally, it <i>must</i> be
 * synchronized externally.  (A structural modification is any operation
 * that adds or deletes one or more elements; merely setting the value of
 * an element is not a structural modification.)  This is typically
 * accomplished by synchronizing on some object that naturally
 * encapsulates the list.
 * 非线程安全的实现
 * If no such object exists, the list should be "wrapped" using the
 * {@link Collections#synchronizedList Collections.synchronizedList}
 * method.  This is best done at creation time, to prevent accidental
 * unsynchronized access to the list:<pre>
 *   List list = Collections.synchronizedList(new LinkedList(...));</pre>
 * 
 * <p>The iterators returned by this class's <tt>iterator</tt> and
 * <tt>listIterator</tt> methods are <i>fail-fast</i>: if the list is
 * structurally modified at any time after the iterator is created, in
 * any way except through the Iterator's own <tt>remove</tt> or
 * <tt>add</tt> methods, the iterator will throw a {@link
 * ConcurrentModificationException}.  Thus, in the face of concurrent
 * modification, the iterator fails quickly and cleanly, rather than
 * risking arbitrary, non-deterministic behavior at an undetermined
 * time in the future.
 *
 * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
 * as it is, generally speaking, impossible to make any hard guarantees in the
 * presence of unsynchronized concurrent modification.  Fail-fast iterators
 * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
 * Therefore, it would be wrong to write a program that depended on this
 * exception for its correctness:   <i>the fail-fast behavior of iterators
 * should be used only to detect bugs.</i>
 *
 * <p>This class is a member of the
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 * Java Collections Framework</a>.
 *
 * @author  Josh Bloch
 * @version 1.67, 04/21/06
 * @see	    List
 * @see	    ArrayList
 * @see	    Vector
 * @since 1.2
 * @param <E> the type of elements held in this collection
 */

public class LinkedList<E>
    extends AbstractSequentialList<E>
    implements List<E>, Deque<E>, Cloneable, java.io.Serializable



1.继承 AbstractSequentialList

2.实现 Deque

二、成员变量及构造方法

    // 
    private transient Entry<E> header = new Entry<E>(null, null, null);
    private transient int size = 0;

    /**
     * Constructs an empty list.
     */
    public LinkedList() {
        header.next = header.previous = header;
    }

    /**
     * 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);
    }






博文参考:
http://www.cnblogs.com/ITtangtang/p/3948610.html
分享到:
评论

相关推荐

    List-LinkedList 单链表就地反转

    ### List-LinkedList 单链表就地反转 #### 概述 本文主要介绍单链表的就地反转算法实现,并通过具体的C语言代码示例来解释这一过程。单链表是一种常见的线性数据结构,其中每个元素包含一个指向下一个元素的指针。...

    使用LinkedList模拟堆栈

    本文将详细讲解如何使用Java中的LinkedList类来模拟这两种数据结构,并实现其基本操作。 堆栈(Stack)是一种后进先出(LIFO, Last In First Out)的数据结构,它遵循“先进后出”的原则。常见的堆栈操作有压栈...

    ArrayList LinkedList Vector区别

    ArrayList LinkedList Vector 区别 ArrayList、LinkedList、Vector 是 Java 中常用的数据结构实现类,它们都实现了 List 接口,但它们在存储方式、性能、线程安全性等方面有着不同特点。 首先,ArrayList 和 ...

    java LinkedList的添加删除操作

    在Java编程语言中,LinkedList是一种线性数据结构,属于集合框架的一部分,实现了List接口和Deque接口。LinkedList以链表的形式存储元素,这使得它在添加和删除元素时具有较高的效率,尤其是在列表的中间或开头进行...

    java中LinkedList任意排序实例

    在Java编程中,LinkedList是一个非常重要的数据结构,它实现了List接口,允许我们在列表的任何位置进行插入和删除操作。LinkedList内部使用双向链表实现,因此它的遍历速度比ArrayList快,但随机访问性能较差。本...

    创建一个 LinkedList项目.docx

    LinkedList 是 Java 中的一种数据结构,属于线性数据结构的一种,但它与数组有着本质的不同。数组在内存中存储元素是连续的,而 LinkedList 则通过节点之间的引用相互连接,每个节点包含元素本身、指向前一个节点的...

    LinkedList的实现.zip

    LinkedList是计算机科学中的一种基本数据结构,特别是在C++编程中,它被广泛用于处理动态集合。LinkedList的主要特点是每个元素(称为节点)包含数据以及指向下一个节点的指针,这种结构使得在列表中间添加或删除...

    JAVA利用LinkedList构造栈与队列

    在Java编程语言中,LinkedList是一个常用的集合类,它实现了List接口,同时也提供了双向链表的实现。LinkedList不仅可以作为列表使用,还可以被巧妙地利用来构建栈(Stack)和队列(Queue)这两种基本数据结构。在本...

    ArrayList LinkedList Vector性能测试

    在Java编程语言中,ArrayList、LinkedList和Vector是三种常见的动态数组实现,它们都在java.util包中,用于存储和管理对象的集合。这三个类都实现了List接口,提供了多种操作方法,但它们在内部实现和性能特性上有所...

    Java 中Linkedlist类的源代码

    在Java编程语言中,LinkedList是一个实现List接口的类,它以双向链表的形式存储元素。这个数据结构允许我们在列表的任何位置进行插入和删除操作,具有O(1)的时间复杂度,这使得LinkedList在需要频繁进行这些操作时比...

    ArrayList和Linkedlist1

    在IT领域,特别是Java编程中,ArrayList和LinkedList是两种非常重要的数据结构,它们都是List接口的实现类。理解这两者的区别对于优化程序性能至关重要。面试官询问这些知识点,旨在评估应聘者的理论基础和实践能力...

    比较ArrayList、LinkedList、Vector1

    【ArrayList、LinkedList、Vector对比分析】 1. **List概述** List接口是Java集合框架中的重要组成部分,它是一个有序的集合,允许重复元素,并且保持插入顺序。List接口的实现类主要有ArrayList、LinkedList和...

    java中LinkedList集合类实现栈和队列.doc

    在Java编程语言中,LinkedList集合类是一个非常重要的数据结构,它可以用来实现栈和队列这两种特殊的数据结构。LinkedList是一个双链表,每个节点包含数据元素和两个引用,分别指向前后节点,这使得在列表中进行插入...

    Java中ArrayList和LinkedList区别 时间复杂度 与空间复杂度1

    在 Java 中,ArrayList 和 LinkedList 是两种常用的集合类,它们各自具有不同的特性和适用场景,主要体现在数据结构、访问效率和操作性能上。 1. 数据结构: - ArrayList 实现了一个动态数组,它内部是一个 Object...

    ArrayList LinkedList Vector性能对比

    ArrayList、LinkedList和Vector是三种常见的动态数组实现,它们各自有特定的特性和使用场景。这里我们将深入探讨这三个类的性能对比,以及它们在不同操作下的表现。 ArrayList是基于动态数组实现的,它提供了随机...

    源码解析jdk7.0集合:LinkedList的底层实现原理.pdf

    在深入分析JDK 7.0中LinkedList集合的底层实现原理前,我们首先需要了解LinkedList的基本概念。LinkedList,即双向链表,是一种通过双向指针相互连接的数据结构,每个节点包含数据域以及指向前驱和后继节点的指针。...

    JavaScript 实现基础 LinkedList 功能

    JavaScript中的LinkedList是一种常见的数据结构,它允许我们在列表的任意位置高效地添加和删除元素。在JavaScript中实现LinkedList,我们需要理解其基本概念、操作以及如何用原生JavaScript对象来模拟链表结构。 ...

    用LinkedList实现队列和栈

    在Java编程语言中,`LinkedList` 是一个常用的集合类,它实现了`List`接口,并且提供了额外的功能,如双端操作。本篇文章将探讨如何利用`LinkedList`来实现队列和栈这两种数据结构,以及其背后的原理和源码分析。 #...

    关于arraylist和linkedList的区别

    ### 关于ArrayList与LinkedList的区别 在Java编程语言中,`ArrayList`与`LinkedList`都是`List`接口的具体实现类,用于存储元素集合。虽然它们都实现了同样的接口并且提供了相同的基本功能,但在内部实现机制、性能...

Global site tag (gtag.js) - Google Analytics