JAVA ArrayList VS linkedlist one-background survey

Source: Internet
Author: User

API Address: http://docs.oracle.com/javase/6/docs/api/

The relationship between the concepts involved is as follows:


Graphic:

The List is an interface that inherits from the collection interface. It represents an orderly queue. It allows for duplicate elements.
Abstractlist is an abstract class that inherits from Abstractcollection. Abstractlist implements a function other than size (), get (int location) in the list interface.
Abstractsequentiallist is an abstract class that inherits from Abstractlist. It has fewer methods. specially designed for LinkedList.
ArrayList, LinkedList, Vector, Stack is the list's 4 implementation classes.

Background one:

ArrayList a object[] array to store the object, note that the array is of type transient. Its add () and remove () methods are passed System.arraycopy (...). Implemented, the Get () method is to return an element of an array.

   ABSTRACTSEQUENTIALLIST  further implements the Add (), get (), and remove () methods. It implements these methods by calling the appropriate methods in the Listiterator class. The goal is to improve execution speed through the characteristics of two-way lists. It declares the listiterator (int index) method as the abstract type, requiring the user to be re-implemented.

LinkedList inherits from Abstractsequentiallistand stores objects through a doubly linked list. Note that the header of this list is of type transient. The header here does not contain the actual data, only as the head node of the list. Its add (), get (), and remove () methods are operations on a doubly linked list. It re-implements the Listiterator (int index) method, defining the embedded Listiterator class through the Bidirectional Link List property.

Background two:

arraylist  is a resizable array. When more elements are added to the ArrayList, their size will grow dynamically. Internal elements can be accessed directly through get and set methods, because ArrayList is essentially an array.
linkedlist 

Source Code Exploration:

ArrayList Source Code Summary:

// size, isEmpty, get, set ,  iterator , and Listiterator Such operations are constant time. The add operation is also close to the constant time. ArrayListAn instance has a property:capacity. Capacity is at least as large as size and it is automatically growing. It represents the number of elements that ArrayList can hold.

ten; //
Object[] Empty_elementdata = {};//capacity is the size of this array buffer
Object[] Elementdata; This is the main element of ArrayList: arrays.
Ensurecapacity (mincapacity);//This method and a series of subsequent methods are used to manipulate capacity, which allows capacity to grow. 
Grow (mincapacity)//This method shows how much each expansion expands, basically equivalent to:1); 
IndexOf (object o)//order to find objects. Linear time
E get (Index)//index Gets the object. Constant time
E Set (index, E Element)//Linear time
Add (e e)//= linear time
Add (index, E Element)//INSERT, linear time
E Remove (index)//delete, linear time














JAVA ArrayList VS linkedlist one-background survey

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.