Single column collection LinkedList
1.LinkedList collection
In many cases, ArrayList is more efficient because you usually need to access a certain element in the list, but LinkedList provides several methods to perform certain operations more efficiently.
2. Source code
3. The difference between ArrayList and LinkedList
The LinkedList class is a collection that can contain many objects of the same type, just like an ArrayList.
The LinkedList class has all the same methods as the ArrayList class because they both implement the List interface.
However, while the ArrayList and LinkedList classes can be used in the same way, they are constructed very differently.
The difference between ArrayList and LinkedList are as follows:
-
ArrayList implements a data structure based on a dynamic array, while LinkedList is a data structure based on a linked list;
-
For random access get and set, ArrayList is better than LinkedList, because LinkedList needs to move the pointer;
-
For adding and deleting operations add and remove, LinkedList is generally faster than ArrayList because ArrayList moves data. Generally, ArrayList is preferred. Since LinkedList can implement data structures such as stacks, queues, and double-ended queues, LinkedList is used when specific needs are required.