LinkedList of the Java collection

Source: Internet
Author: User
Tags prev serialization

What is 1.LinkedList? What are the characteristics

LinkedList is an ordered sequence that can be efficiently inserted and removed at any location, based on a doubly linked list.

LinkedList is a doubly linked list that inherits from Abstractsequentiallist. It can also be manipulated as a stack, queue, or double-ended queue.
The LinkedList implements the List interface and can queue operations on it.
LinkedList implements the Deque interface, which means that linkedlist can be used as a double-ended queue.
LinkedList implements the Cloneable interface, which covers the function clone () and can be cloned.
The LinkedList implements the Java.io.Serializable interface, which means that the LinkedList supports serialization and can be transmitted by serialization.
The LinkedList is non-synchronous.

2.LinkedList Source Code Analysis 2.1 The basic structure of the node
Private Static class Node<e> {        E item;    // represents the value        that the node contains // expresses the next node        of the current node // represents the previous node of the current node         Node (node<E> prev, E element, node<e> next) {            this. Item = element;             this. Next = next;             this. prev = prev;        }    }
2.2 Adding operations
   Public BooleanAdd (e e) {linklast (e); return true; } 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++; }

Insert specified position

 Public voidAddintindex, E Element) {       //Check to see if it crossesCheckpositionindex (index); //The last one calls the add        if(Index = =size) linklast (element); //Middle Position Call Linkbefore        ElseLinkbefore (element, node (index)); }voidLinkbefore (e E, node<e>succ) {        //assert succ! = null;        Finalnode<e> pred =Succ.prev; FinalNode<e> NewNode =NewNode<>(Pred, E, succ); Succ.prev=NewNode; if(Pred = =NULL) First=NewNode; ElsePred.next=NewNode; Size++; Modcount++; }     

LinkedList of the Java collection

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.