Home > Java > Javagetting Started > What are the differences between ArrayList, LinkedList and Vector?

What are the differences between ArrayList, LinkedList and Vector?

王林
Release: 2020-08-06 16:01:03
forward
4845 people have browsed it

What are the differences between ArrayList, LinkedList and Vector?

1. Analysis from the storage data structure

(Recommended tutorial: java introductory tutorial)

ArrayList: Array

Vector: Array

LinkedList: Doubly linked list

Array: You can quickly search based on the subscript, so in most cases, the query is fast.

But if you want to perform addition and deletion operations, you will need to move all the elements behind the modified element, so the overhead of additions and deletions is relatively large, and the execution efficiency of the array's addition and deletion operations is low. ArrayList and Vector, which use arrays as data storage structures, also have these characteristics. The query speed is fast (can be retrieved directly based on the subscript, which is faster than iterative search), and the addition and deletion are slow.

Linked list: It is convenient to add and delete elements. To add or delete an element, you only need to deal with the references between nodes. Just like people holding hands in a row, if you want to add or delete someone, you only need to change the two people nearby to hold hands with another person, and it will have no effect on the people who are already holding hands. The resources and time consumed by substitution are the same no matter where.

But the query is inconvenient. It needs to be compared one by one, and it cannot be directly searched based on the subscript. LinkedList, which is stored in a linked list structure, also has these characteristics. It is easy to add and delete, but slow to query (referring to random query, not sequential query).

2. Analysis from the perspective of inheritance

What are the differences between ArrayList, LinkedList and Vector?

They all implement the List interface, which means they all implement get(int location ), remove(int location) and other "functions to obtain and delete nodes based on index values".

(Video tutorial recommendation: java video tutorial)

It is easy to get the value of the array structure according to the subscript, and the implementation of the LinkedList bidirectional list is also relatively simple, by counting the index value To implement, search starts from 1/2 the length of the linked list. If the subscript is larger, it will start searching from the head of the list. If it is smaller, it will start searching from the end of the list.

3. Analysis from the perspective of concurrency safety

Vector: thread safety

ArrayList: non-thread safety

LinkedList: non-thread Security

4. Data growth analysis

Vector: By default, the growth is twice the length of the original array. Speaking of default, it means that he can actually set the initialization size independently.

ArrayList: Automatically grows 50% of the original array.

The above is the detailed content of What are the differences between ArrayList, LinkedList and Vector?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template