当前位置:网站首页>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



边栏推荐
- Enhance network security of kubernetes with cilium
- MySQL indexes and transactions
- Floyd AcWing 854. Floyd求最短路
- drools执行String规则或执行某个规则文件
- BOM DOM
- Redis avalanche, penetration, breakdown
- arcgis js 4. Add pictures to x map
- The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
- CDA data analysis -- Introduction and use of aarrr growth model
- [ybtoj advanced training guidance] judgment overflow [error]
猜你喜欢

Sparkcontext: error initializing sparkcontext solution

Addition, deletion, modification and query of MySQL table (Advanced)

线性DP AcWing 902. 最短编辑距离

Record the range of data that MySQL update will lock

CDH6之Sqoop添加数据库驱动

CDA数据分析——AARRR增长模型的介绍、使用

Simple understanding of ThreadLocal

分布式机器学习框架与高维实时推荐系统

Lekao.com: experience sharing of junior economists and previous candidates in customs clearance

Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
随机推荐
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
CDA data analysis -- Introduction and use of aarrr growth model
LeetCode—剑指 Offer 51. 数组中的逆序对
Sparkcontext: error initializing sparkcontext solution
寻找二叉树中任意两个数的公共祖先
Sse/avx instruction set and API of SIMD
Lombok common annotations
Fastdateformat why thread safe
Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
Simple understanding of ThreadLocal
染色法判定二分图 AcWing 860. 染色法判定二分图
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
趣味 面试题
线性DP AcWing 898. 数字三角形
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
BOM DOM
BOM DOM
CDH6之Sqoop添加数据库驱动
"As a junior college student, I found out how difficult it is to counter attack after graduation."