List in the data structure is expressed as a linear table, its elements are stored in a linear manner, the collection allows to store duplicate objects, list interface main implementation class has
as far as the data structure is concerned, the corresponding way of it is divided into one to one, 0 to 0, one to many, many to many. In the data structure is a linear table, a set, a tree, a graph. And list is a linear table.
ArrayList
ArrayList is actually a set of variable-length arrays, when an ArrayList is instantiated, the data is instantiated, and when an object is added to the collection, the size of the array changes as well, so it has the advantage of fast random access, Even though the performance problems of accessing each element are small, the downside is that you want to add or remove objects slowly, and when you create an array that is not sure of its capacity, we have to do a lot of processing in memory when we change the array, such as if you want to add an object to the middle of any two elements in the array. Then in the in-memory array to move all subsequent objects.
variable array The meaning of these words is that his nature is still an array, the characteristic of the array is a contiguous memory, and the reading speed is very fast, because it can be accessed according to the subscript, directly hit. add needs to move the data, the corresponding get and set need to be directly hit
LinkedList
LinkedList is the data structure of the linked list through the connection of the node, the speed of inserting or deleting elements into the LinkedList is very fast, and the speed of random access is relatively slow, this is due to the nature of the linked list itself, in the list, each node contains a reference to the previous node, After a node's reference and node storage values, when a new node is inserted, only the relevant front and back relationship node references need to be modified, and the node is deleted as well. The operand only needs to change the link of the node, and the new node can be stored anywhere in the memory, but also because of this linkedlist although there is a get () method, but this method by traversing the node to locate so slow. LinkedList also has a separate addfrist (), AddLast (), Getfrist (), GetLast (), Removefirst (), Removelast () methods that enable LinkedList to act as a stack, a queue , and dual queues to use.
Plainly, ArrayList and LinkedList are sequential storage tables and chained storage tables in data structures.
Java Source Code Analysis list