ArrayList and LinkedList in java

【summarize】

There are two kinds of lists commonly used in java: ArrayList and LinkedList

ArrayList is good at finding elements

LinkedList is good at adding and removing elements

The bottom layer of ArrayList is an array, which makes it extremely fast to find elements regardless of the size of the data. Because of the array structure, each element has a corresponding index; if you want to add or delete operations in ArrayList, you need to add new ones. All elements after the element position are moved back one place, and the speed is naturally very slow.

The bottom layer of LinkedList is a doubly linked list. If you want to find elements through linkedList, you need to add indexes to each element one by one, and then search according to the index. The larger the amount of data, the slower the speed. If it is to add or delete elements, you only need to delete the connection between the two elements before and after the new element, and establish a two-way pointing between the new element and the two elements before and after. That is, only these two elements are affected, so LinkedList is added and deleted quickly.



The list in redis uses LinkedList.

Why did redis choose linked list?

Among the Redis operations, the most common operation is to add or delete elements.

Use environment:

   Add and delete large data sets

  task queue

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325842485&siteId=291194637