当前位置:网站首页>The difference between LinkedList and ArrayList
The difference between LinkedList and ArrayList
2022-07-26 07:54:00 【I like iced black tea】
data structure
ArrayList Is the implementation of a dynamic array based data structure , During initialization , If the array size is not specified , The default size of the application is 10 Array of , When the number of elements increases , When an array cannot be stored , The system will be expanded (grow), The length of the new array is... Of the original length 1.5 times , Then copy the previous data to the new array .
LinkedList Is based on the two - way circular linked list , A two-way linked list contains two pointers ,pre Point to previous node ,next Point to the next node , But the first node head Of pre Point to null, Of the last node tail Point to null. The values are stored in item in ,LinkedList There is no concept of length , Therefore, there is no problem of insufficient capacity , Therefore, there is no need to provide a constructor of the initialization size , Therefore, only two methods are provided , One is the nonparametric construction method , The first one LinkedList object , One is and designated aggregate Elements converted to LinkedList Construction method .
Access elements
For random access ArrayList The speed of is absolutely better than LinkedList. because ArrayList The data structure of is a dynamic array , We can directly use subscript pairs ArrayList Conduct get and set operation , and LinkedList It's a two-way circular list , Need to traverse .
Add and delete
For addition and deletion ,LinkedList Is better than ArrayList, Because in ArrayList Need to move data , When the added element is larger than the length of the array , It also needs to be expanded , In addition, the more forward the position , The more elements you need to move , The more expensive it is . and LinkedList You only need to modify the previous element or the next element pre Point to and next Just point .
LinkedList Method and use of ArrayList Almost the same , because LinkedList It's a linked list , So it's extra to add... At the head and tail / How to delete elements , There is no ArrayList The problem of capacity expansion .
边栏推荐
猜你喜欢

No valid host was found when setting up openstack to create an instance There are not enough hosts available. code:500

一文掌握mysql数据库审计特点、实现方案及审计插件部署教程

《门锁》引爆独居安全热议 全新海报画面令人窒息

Use of JMeter performance test to store response content to file listener

以太网交换安全

Summary of distributed related interview questions

JMeter performance test saves the results of each interface request to a file

FTP service

20220209 create a basic Servlet

分布式相关面试题总结
随机推荐
Pycharm common shortcut keys
Jmeter性能测试之将每次接口请求的结果保存到文件中
FTP service
Vscode cannot start the problem solving idea
Deep learning model deployment
NFS service and Samba service deployment
"Door lock" ignites a heated discussion on the safety of living alone. The new poster picture is suffocating
Solution to the problem of token loss when microservice feign is called
20220209 create a basic Servlet
Summary of common methods of string
OVSDB
ShardingSphere数据分片
Unity metaverse (II), mixamo & animator hybrid tree and animation fusion
Next item recommendations in short sessions
Distributed system and distributed database system (Introduction)
Practice of online question feedback module (XIV): realize online question answering function
Lambda and stream
JMeter performance test saves the results of each interface request to a file
How to determine the authenticity of the website you visit -- certificate system
Speech at 2021 global machine learning conference