The difference between ArrayList and LinkedList
1.ArrayList is based on an array, LinkedList is based on a linked list implementation.
For ArrayList and LinkedList, the overhead of adding an element at the end of the list is fixed.
For ArrayList, the main point is to add an entry to the inner array, pointing to the added element, which may occasionally cause the array to be reassigned;
For LinkedList, this overhead is uniform and allocates an internal entry object.
2. for random access get and set,arraylist feel better than LinkedList, because linkedlist to move the pointer.
3. Add and Remove,linedlist are the dominant for new and deleted operations because ArrayList is moving the data.
Inserting or deleting an element in the middle of a ArrayList means that the remaining elements in the list will be moved;
The overhead of inserting or deleting an element in the middle of a linkedlist is fixed.
4. find operation Indexof,lastindexof,contains and so on, both similar.
5.ArrayList space waste is mainly reflected in the list at the end of a certain amount of space reserved, and the linkedlist of the space cost is reflected in each of its elements need to consume considerable space
This is only a theoretical analysis, in fact, not necessarily, such as ArrayList at the end of the insertion and deletion of data is not designed to move data, but there is a suggestion:LinkedList does not support efficient random element access , Random access more than the words must be used ArrayList instead of LinkedList, if you need frequent insertions and deletions should consider using LinkedList to improve performance.
6. About expansion
The initial capacity of the Arraylis is 10,
When the capacity is not enough
Re-open a space of 1.5 times times +1
Copy the data.
It can be said that using ArrayList provides better performance when the action is to add data after a column of data rather than in front or in the middle, and to randomly access its elements, and when your action is to add or delete data in front or in the middle of a column of data, and to access its elements sequentially, You should use the LinkedList. ArrayList
Collection of Java Basics