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



边栏推荐
- arcgis js 4.x 地图中加入图片
- 模块化 CommonJS ES Module
- Sse/avx instruction set and API of SIMD
- 甜心教主:王心凌
- Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
- (C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?
- Go学习笔记—基于Go的进程间通信
- 记录一下MySql update会锁定哪些范围的数据
- 哈希表 AcWing 840. 模拟散列表
- 2.7 binary tree, post order traversal - [FBI tree]
猜你喜欢
随机推荐
Map and set
Openssh remote enumeration username vulnerability (cve-2018-15473)
CPU指令集介绍
Lombok common annotations
[C language] Yang Hui triangle, customize the number of lines of the triangle
Go学习笔记—多线程
(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
AI mid stage technology research
(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?
CDA data analysis -- common knowledge points induction of Excel data processing
Intel internal instructions - AVX and avx2 learning notes
哈希表 AcWing 840. 模拟散列表
Docker-compose配置Mysql,Redis,MongoDB
Anti shake throttle
线性DP AcWing 899. 编辑距离
深拷贝 事件总线
线性DP AcWing 895. 最长上升子序列
bellman-ford AcWing 853. 有边数限制的最短路
Input a three digit number and output its single digit, ten digit and hundred digit.
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了








