In-depth understanding of LinkedList
一、LinkedList
1. Storage principle
LinkedList is a linked list, with a front node and a rear node before and after the elements, which are used to connect the previous element and the next element in the set, and "hand in hand" in turn to form a set of chained data.
2. Unique method
3. Comparison with ArrayList collection
1. The List interface stores a set of objects that are not unique (can be repeated) and ordered (insertion order)
2. ArrayList implements a variable-length Object type array, allocates continuous space in memory, and traverses elements and randomly accesses elements more efficiently
3. LinkedList adopts linked list storage method, which is more efficient when inserting and deleting elements
4. Compare the difference between the two structures by viewing the source code of the adding method. Chain storage and array storage
Reasons for different efficiency:
Linkedlist will only affect the two adjacent elements when performing delete and add operations.
Since Arraylist is an array in nature, the address values of all subsequent elements will be shifted when performing delete and add operations.
4. In-depth understanding through source code and drawing
code show as below(
to sum up
The above is all the content of the in-depth understanding of LinkedList in the Java collection, mainly using its principles, methods, and source code and drawing methods for in-depth understanding.