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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
