The difference between "Java" ArrayList, Vector, LinkedList

Source: Internet
Author: User

ArrayList, Vector, LinkedList belong to the list interface, all exist in the Java.util package, are scalable arrays, can dynamically change the length.

Both ★arraylist and vectors are implemented based on the storage element object[] array, which opens up a contiguous space in memory for storage because the data stores are contiguous, so they support the use of subscripts to access the data . And the index data is faster, and because the storage is contiguous, the data is moved when the new element is inserted, so it is slower to execute when inserting the data.

In the undefined capacity of large hours, ArrayList and vectors have an initial capacity size, when the data stored in more than this initialization capacity, they will dynamically expand the storage space, and in order to improve the efficiency of the program, each expansion is not simply to add a storage unit, ArrayList default expansion is 1.5 times times the original ( cannot customize the size of each expansion space), thevector will be expanded by default to the original twice Times ( can be customized to set the size of the expansion space).

ArrayList and vector The biggest difference is the use of synchronization synchronization,there is no method in ArrayList synchronization , and the majority of vectors are directly or indirectly synchronous , so vectors are thread-safe and ArrayList are not thread -safe, but also because of the vector's thread-safety mechanism, which makes them less powerful than ArrayList.

Sequential storage similar to sequential tables in data structures

★linkedlist uses a two-way list because its data storage is not stored sequentially, so the data needs to be traversed from the beginning , while the use of linkedlist is less efficient when there is a need for random access, but It has the advantage of not having to move data when inserting data, LinkedList is a non-thread-safe container.

Chained storage similar to sequential tables in data structures

★ Selection Principle:

(1) When the operation of the data is mainly indexed or only at the end of the collection of data additions and deletions, the use of ArrayList and vector efficiency will be relatively high.

(2) When the operation of the data is mainly in the specified location for adding and removing, the use of LinkedList efficiency will be relatively high.

(3) When multiple threads are required to access the container at the same time, using vectors is more secure

The difference between "Java" ArrayList, Vector, LinkedList

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.