What is the difference between ArrayList (array) and LinkedList (doubly linked list)? Reasons to use ArrayList instead of LinkedList

@[toc](What is the difference between ArrayList (array) and LinkedList (doubly linked list)? Reasons for using ArrayList instead of LinkedList)



What is the difference between ArrayList (array) and LinkedList (doubly linked list)?

  • ArrayList: The interior is implemented through an array, supports random access, implements RandomAccessthe interface, implements Serializablethe interface, implements Cloneablethe interface, thread is not safe, and has high efficiency
  • LinkedList: The interior is implemented through a linked list, does not support random access, does not implement RandomAccessthe interface, implements Serializablethe interface, implements Cloneablethe interface, the thread is not safe, and the efficiency is high

Reasons to use ArrayList instead of LinkedList

  • Insertion: ArrayList tail insertion efficiency is high, and LinkedList head and tail insertion efficiency is high. But the insertion efficiency is very low, because ArrayList needs to move elements, and LinkedList needs to move pointers.
  • Deletion: ArrayList tail deletion is efficient, and LinkedList head and tail deletion is efficient. But intermediate deletion is very inefficient, because ArrayList needs to move elements, and LinkedList needs to move pointers.
  • Modification: Random access efficiency of ArrayList is high, and random access efficiency of LinkedList is low.
  • Query: ArrayList has high random access efficiency, and LinkedList has low random access efficiency.
    So we just use ArrayList.






My Github address , welcome everyone to join my open source project, or (contact me on my homepage) to join your open source project, click Github-Stars.

\ open source project name dependent type version number describe
1 spring-boot-starter-trie pom 1.0.0-SNAPSHOT The query speed under specific requirements far exceeds that of open source search tools, and the B+ tree under innodb or the inverted index in ES cannot compare with it.
2 spring-boot-starter-trie jar 1.0.0-M1 Provides SpringCloud-based service nodes, which can be used for service discovery through the Nacos registry, realizing dynamic expansion and contraction of the tree, and dynamic online and offline services.
3 Data-Provider pom 1.0.0-SNAPSHOT It provides queries from multiple data sources and data type synchronization. As a Jar, it can rely on dynamically providing data on other services.

Guess you like

Origin blog.csdn.net/jj89929665/article/details/130908743