The difference between JSP ArrayList and LinkedList and the characteristics of ArrayList

Source: Internet
Author: User
Tags arrays static class

Web effects phttp://www.111cn.net/Web effects p.html target=_blank >jsp Tutorials ArrayList and LinkedList differences and characteristics of ArrayList

ArrayList)
Private transient object[] elementdata;



..........................................................................................

(LinkedList)
Private transient entry<e> Header = new entry<e> (null, NULL, NULL);/list Header



Internal linked list class.

private Static Class Entry<e> {
e element; Data elements
Entry<e> Next; Precursor
Entry<e> previous;//Rear Drive
Entry (e element, entry<e> Next, entry<e> previous) {
This.element = element;
This.next = Next;
This.previous = previous;
}
}   


/*
No doubt, the 1th is that the internal data structure of the two is different, the ArrayList inner element container is an object array,
and LinkedList inside actually a list of data structure, it has an internal class to represent the linked list.
The different parent classes of the two determine the different storage forms of the two. ArrayList inherits from Abstractlist, and LinkedList inherits from Abstractsequentiallist. Both achieve the backbone of the list, only the former access to the form of "random Access" data storage (such as arrays), the latter tend to "continuous access" data storage (such as linked lists)

*/

Public
class Arraylist<e> extends abstractlist<e>
public class Linkedlist<e> extends abstractsequentiallist<e>


/*
Then there is the efficiency of both, ArrayList based on the array implementation, so there is no doubt can be directly indexed by subscript, its index data fast, insert elements designed to move the elements of the array, or array expansion, so the insertion element is slow. LinkedList based on the linked list structure, the insertion element only needs to change the insertion of the elements before and after the point, so the insertion of data quickly, and the index elements need to traverse backwards, so the index element is slow.
*/

public void ensurecapacity (int mincapacity) {
modcount++;
int oldcapacity = Elementdata.length;
if (Mincapacity > Oldcapacity) {
Object olddata[] = Elementdata;
Here the enlarged size is about 60% of the original size
int newcapacity = (oldcapacity * 3)/2 + 1;
if (Newcapacity < mincapacity)
newcapacity = mincapacity;
Creates a new array of the specified size to overwrite the original array
Elementdata = arrays.copyof (Elementdata, newcapacity);
}
   }   
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.