How to use LinkedList and ArrayList
This article mainly explains "how to use LinkedList and ArrayList". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use LinkedList and ArrayList.
For the respective usage scenarios of LinkedList and ArrayList, how to confirm which one should be used?
In a nutshell, it is better to use ArrayList in most cases.
Time-consuming has its own advantages and disadvantages. ArrayList has a slight advantage List is just an interface, while LinkedList and ArrayList are different implementations of List. LinkedList's model is a two-way linked list, while ArrayList is a dynamic array.
First of all, compare the algorithm complexity of common operations.
LinkedList
Get (int index): O (n)
Add (E element): O (1)
Add (int index, E element): O (n)
Remove (int index): O (n)
Iterator.remove (): O (1)