41. Java single-column collection LinkedList

1.LinkedList collection

insert image description here
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.
insert image description here

2. Source code

insert image description here

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:

  1. ArrayList implements a data structure based on a dynamic array, while LinkedList is a data structure based on a linked list;

  2. For random access get and set, ArrayList is better than LinkedList, because LinkedList needs to move the pointer;

  3. 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.

Guess you like

Origin blog.csdn.net/u014217137/article/details/130440173