Java Collection Class-linkedlist analysis

Source: Internet
Author: User
Tags prev

LinkedList features non-thread-safe support for serializing doubly linked list member variables

transient int size = 0;
Transient node<e> first; Point to first element
Transient node<e> last; Point to last Element

Linked list nodes, three attributes: element, previous node, next node

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

Basic method Add
 Public BooleanAdd (e e) {linklast (e); return true;}voidLinklast (e e) {FinalNode<e> lasttmp =Last ; FinalNode<e> NewNode =NewNode<> (Lasttmp, E,NULL); Last=NewNode; if(Lasttmp = =NULL) First=NewNode;; Size++; Modcount++;}

Delete Remove
 PublicE Removelast () {Finalnode<e> L =Last ; if(L = =NULL)        Throw Newnosuchelementexception (); returnUnlinklast (l);}PrivateE Unlinklast (node<e>l) {//assert L = = Last && L! = null;    FinalE element =L.item; FinalNode<e> prev =L.prev; L.item=NULL; L.prev=NULL;//Help GCLast =prev; if(prev = =NULL) First=NULL;; Size--; Modcount++; returnelement;}

The principle of changing the Set check get expansion

Add new nodes backwards

Some questions reference

Java Collection Class-linkedlist analysis

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: 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.