*
Arraylist: The bottom layer is based on dynamic arrays , According to the following table, random access to array elements is efficient , It is efficient to add elements to the end of an array ; however , It is inefficient to delete the data in the array and add data to the middle of the array , Because the array needs to be moved . For example, the worst case scenario is to delete the first array element , You need to change the 2 To n Array elements are moved forward one bit each . It is called dynamic array , Because Arraylist The array element is larger than its capacity ,Arraylist It can be expanded ( in the light of JDK1.8 
The capacity of the expanded array is before the expansion 1.5 times ),Arraylist The maximum array capacity in the source code is Integer.MAX_VALUE-8, For the vacant 8 position , The current explanation is
:① storage Headerwords;② Avoid some machine memory overflow , Reduce the chance of making mistakes , So less distribution ③ The biggest is still able to support Integer.MAX_VALUE( When Integer.MAX_VALUE-8 Still unable to meet demand ). Here are Arraylist Part of the source code :
* Arraylist Expansion :
*

* Arraylist Add data :( Add to end of array )
*
* Adds an array to the specified position of the array :
*
You can see , as long as ArrayList The current capacity of is large enough ,add() Operation to the end of the array is very efficient , When adding data to the specified position of the array , There will be a large number of array move copy operations . When the array is copied , Finally, the System.arraycopy() method , therefore add() The efficiency of operation is quite high . Even so, when you add data to the specified location, it's still better than Linkedlist slow , The latter only needs to change the pointer to add data .Arraylist Deleting arrays also requires moving arrays , Slower efficiency .
* Linkedlist Dynamic array based on linked list , High efficiency of data addition and deletion , Just change the pointer , But the average efficiency of accessing data is low , You need to traverse the linked list .
* Arraylist get Source code of data :( Access according to subscript , efficient )
*
* Linkedlist Source code for accessing data :(node() Function traversal list )
*
*
*  
* summary :1, For random access get and set,ArrayList be better than LinkedList, because LinkedList To move the pointer . 
                 For add and delete operations add and remove,LinedList Comparative advantage , because ArrayList To move data .
*            2, Respective efficiency :
*
 

 

Technology
©2019-2020 Toolsou All rights reserved,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing