JDK Source Reading Notes Java Collection framework (iv) (LinkedList)

Source: Internet
Author: User

The analysis of LinkedList will start with and only from its Add method.

Because the previous article has analyzed the ArrayList, the similar place no longer narrates, the attention point in the linkedlist characteristic.

Property:

   /**      * List head *      /     transient node<e> first ;     /** * The       Tail of the chain * /    transient node<e> last;
View Code

From the above two attributes, we can conclude that LinkedList is based on a doubly linked list.

Node code (without too much explanation):

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;        }    }
View Code

LinkedList the Add Method:

There are multiple add methods in the LinkedList, which is the same, then select one to analyze.

/*** Insert the specified element to the list tail*/     Public BooleanAdd (e e) {linklast (e); return true; }    /*** Links e as last element. */    voidLinklast (e e) {Finalnode<e> L =Last ; FinalNode<e> NewNode =NewNode<> (L, E,NULL); Last=NewNode; if(L = =NULL) First=NewNode; ElseL.next=NewNode; Size++; Modcount++;//This series of blogs is explained in detail}

JDK Source Reading Notes Java Collection framework (iv) (LinkedList)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.