ArrayList and LinkedList compare

in use List When , It is often used ArrayList and LinkedList, But when should it be used ArrayList, When to use LinkedList, Here is a brief explanation .

ArrayList principle

ArrayList It actually corresponds to an array of data structures (Array).

ArrayList The data storage structure of is an array . Arrays are characterized by :

* Occupied space fixed , But when there's not much data , Waste of space ;
* When inserting data , Because the space size is fixed , So there's no need to allocate space for the data , Just insert the data . But when inserting , The data behind needs to be moved . Slower ;
* When deleting data , It is necessary to move the data behind the space . Slower ;
* When getting the specified location data , You can use the subscript of the data to locate directly . Fast ;
LinkedList principle

LinkedList In fact, it corresponds to the linked list in the data structure .

LinkedList The data storage structure of is linked list . In particular, linked lists :

* The space occupied is not fixed , Dynamic allocation with data size , No waste of space ;
* When inserting data , Need to allocate space dynamically , And then insert it . The latter data does not need to be moved . Fast ;
* When deleting data , Delete directly , And free up space . The latter data does not need to be moved . Fast ;
* When getting the specified location data , Unable to locate directly , Need to find one by one , Until the corresponding data is found , Slow ;
ArrayList and LinkedList compare

According to the above face ArrayList and LinkedList Explanation of principle , The summary is as follows .

ArrayList and LinkedList Comparison of characteristics

ArrayList LinkedList
Insert operation Slow
Delete operation Slow
Get the specified location data Fast
ArrayList and LinkedList purpose

If the operation focuses on inserting , delete , Then use it LinkedList bar , It's fast ;

If the operation is focused on getting the specified location data , Then use it ArrayList, It's fast ;

notes : The operation to get the data of the specified location , At present, we can find it , Ergodic, etc .

notes : About what is an array (Array), What is a linked list . Let's take a look at the data structure , Or Baidu , Self invigorating brain . ha-ha

Technology
©2019-2020 Toolsou All rights reserved,
Send love - A little romance for programmers VHDL—— Design of frequency divider Python Implementation of Hanoi Tower code It's over , Starting salary 30khtml+css+js Make a simple website home page QQ Login interface implementation Hill sorting of sorting algorithm ——c++ realization 【 Wechat applet learning 】 Netease music cloud code page implementation details Resume the 13th session python Blue Bridge Cup 2022 Solution to the 13th Blue Bridge Cup ( whole )