What is the difference between ArrayList and LinkedList in java?

王林
Release: 2020-02-10 18:02:56
forward
2346 people have browsed it

What is the difference between ArrayList and LinkedList in java?

The differences are as follows:

Both ArrayList and LinkedList implement the List interface. However, in terms of data structure implementation, ArrayList is an array, and LinkedList is a doubly linked list, so LinkedList consumes more memory than ArrayList because it needs to store two references per node, one pointing to the previous element and one pointing to the next element. The time complexity of searching for elements in an array is O(1), and the time complexity of searching for elements in a linked list is O(n). Therefore, when there are many queries, ArrayList is more suitable than LinkedList.

(Free learning video tutorial sharing:java video tutorial)

So what if it is an addition or deletion operation?

As long as there are no addition or deletion operations at the beginning or end, the efficiency of LinkedList is higher than that of ArrayList, because after ArrayList performs addition and deletion operations, some data in the array will be affected, and the subscripts need to be replaced. The affected data The wider the range, the lower the efficiency.

Recommended related articles and tutorials:java introductory tutorial

The above is the detailed content of What is the difference between ArrayList and LinkedList in java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!