The LinkedList of important Java classes

Source: Internet
Author: User
Tags addall object object

First, ArrayList and LinkedList

Basic Concepts: The list is an interface, ArrayList and LinkedList are two of its implementation classes, but they are implemented differently. I have implemented the structure and basic method of single-linked list in the article "single-linked list Java implementation", here is to say that the LinkedList is the Java package good doubly linked list data structure, and ArrayList is implemented by an array, it is not a real linked list, At initialization time, it sets an initial capacity of an array, and when there is not enough space, it will rebuild a larger array and then copy the previous elements. Roughly speaking, the difference between ArrayList and LinkedList is essentially the difference between the two types of data structures, arrays and lists.

Approximate differences:

Ignoring special circumstances, generally speaking, the two have the following differences
1.ArrayList is a data structure based on dynamic array, LinkedList data structure based on linked list.
2. Find elements/Read data: For random access Get and set,arraylist performance is better than linkedlist,arraylist directly according to the subscript can be accessed, and the LinkedList traversal is to move the pointer step-by-step.
3. Additions/deletions: Add and remove,linedlist are more dominant, and their time is mainly spent on moving pointers. While ArrayList adds the need to move elements back, removing the need to move the elements forward, moving the data is time consuming.  

II. Structure of LinkedList

LinkedList is a doubly linked list structure.

The LinkedList contains two important members: header and size. the header is the table header of the doubly linked list, which is an instance of the class entry corresponding to the doubly linked list node . Size is the number of nodes in a doubly linked list.

Entry contains member variables: Previous, Next, element. Where previous is the node's previous node, next is the node's next node, and element is the value that the node contains.

Third, LinkedList API

1 LinkedList's API2 BooleanAdd (E object)3 voidAddintLocation , E object)4 BooleanAddAll (collection<?extendsE>collection)5 BooleanAddAll (intLocation, collection<?extendsE>collection)6 voidAddFirst (E object)7 voidaddlast (E object)8 voidClear ()9 Object Clone ()Ten Booleancontains (Object object) OneIterator<e>Descendingiterator () A E Element () -E Get (intLocation ) - E GetFirst () the E getlast () - intindexOf (Object object) - intlastIndexOf (Object object) -Listiterator<e> Listiterator (intLocation ) + BooleanOffer (E o) - BooleanOfferfirst (e e) + BooleanOfferlast (e e) A E-Peek () at E Peekfirst () - E peeklast () - E poll () - E Pollfirst () - E polllast () - E pop () in voidpush (e E) - E Remove () toE Remove (intLocation ) + Booleanremove (Object object) - E Removefirst () the Booleanremovefirstoccurrence (Object o) * E removelast () $ Booleanremovelastoccurrence (Object o)Panax NotoginsengE Set (intLocation , E object) - intsize () the<T>t[] ToArray (t[] contents) +Object[] ToArray ()

The LinkedList of important Java classes

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.