当前位置:网站首页>ArrayList与LinkedList效率的对比
ArrayList与LinkedList效率的对比
2022-07-02 09:43:00 【牧歌ing】
ArrayList与LinkedList效率的对比
看了网上很多文章都说,ArrayList的查询效率优于LinkedList,而增删效率低于LinkedList。这种说法其实是有问题的,ArrayList底层是数组,插入其实就是在尾部添加,确实在扩容的时候会损失一点效率,但这点损失基本不需要考虑。
下面将用百万数据进行一个测试
首先看增加
long s=System.currentTimeMillis();
ArrayList arrayList=new ArrayList();
for (int i = 0; i < 1000000; i++) {
arrayList.add(i);
}
System.out.println("ArrayList尾插 "+(System.currentTimeMillis()-s));
s=System.currentTimeMillis();
LinkedList linkedList=new LinkedList();
for (int i = 0; i < 1000000; i++) {
linkedList.add(i);
}
System.out.println("LinkedList增加 "+(System.currentTimeMillis()-s));
结果是ArrayList的速度要优于LinkedList
删除
long s=System.currentTimeMillis();
String str="";
for (int i = 999999; i > -1; i--) {
arrayList.remove(i);
}
System.out.println("ArrayList尾删 "+(System.currentTimeMillis()-s));
s=System.currentTimeMillis();
for (int i = 999999; i > -1; i--) {
linkedList.removeLast();
}
System.out.println("linkedList尾删 "+(System.currentTimeMillis()-s));
结果是ArrayList的速度优于LinkedList
多执行几遍也是ArrayList的增删速度优于LinkedList



边栏推荐
- Is the neural network (pinn) with embedded physical knowledge a pit?
- 计数类DP AcWing 900. 整数划分
- Distributed machine learning framework and high-dimensional real-time recommendation system
- Shutter encapsulated button
- The blink code based on Arduino and esp8266 runs successfully (including error analysis)
- 线性DP AcWing 897. 最长公共子序列
- [FFH] little bear driver calling process (take calling LED light driver as an example)
- Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution
- China traffic sign detection data set
- 单指令多数据SIMD的SSE/AVX指令集和API
猜你喜欢

Heap (priority queue)
![[FFH] little bear driver calling process (take calling LED light driver as an example)](/img/e7/153ae9f1befc12825d277620049f9d.jpg)
[FFH] little bear driver calling process (take calling LED light driver as an example)

线性DP AcWing 902. 最短编辑距离
![[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol](/img/13/9002244555ebe8a61660c2506993fa.png)
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol

刷题---二叉树--2

记录一下MySql update会锁定哪些范围的数据

Use sqoop to export ads layer data to MySQL

High performance erasure code coding

区间DP AcWing 282. 石子合并

浏览器存储方案
随机推荐
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
Map and set
防抖 节流
Multiply LCA (nearest common ancestor)
Distributed machine learning framework and high-dimensional real-time recommendation system
Leetcode - Sword finger offer 51 Reverse pairs in an array
Simple understanding of ThreadLocal
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
Jenkins user rights management
Input box assembly of the shutter package
arcgis js 4.x 地图中加入图片
Anti shake throttle
Shuttle encapsulated AppBar
CDA数据分析——AARRR增长模型的介绍、使用
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
使用Sqoop把ADS层数据导出到MySQL
ThreadLocal的简单理解
IPhone 6 plus is listed in Apple's "retro products" list
LeetCode—剑指 Offer 51. 数组中的逆序对
趣味 面试题