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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool





