当前位置:网站首页>Efficiency comparison between ArrayList and LinkedList
Efficiency comparison between ArrayList and LinkedList
2022-07-02 12:41:00 【Pastoral ing】
ArrayList And LinkedList Comparison of efficiency
I read many articles on the Internet and said ,ArrayList The query efficiency of is better than LinkedList, The efficiency of adding and deleting is lower than LinkedList. There is a problem with this statement ,ArrayList At the bottom is an array , Inserting is actually adding , Indeed, a little efficiency will be lost during capacity expansion , But this loss basically doesn't need to be considered .
Next, we will conduct a test with millions of data
First, look at the increase
long s=System.currentTimeMillis();
ArrayList arrayList=new ArrayList();
for (int i = 0; i < 1000000; i++) {
arrayList.add(i);
}
System.out.println("ArrayList Tail insertion "+(System.currentTimeMillis()-s));
s=System.currentTimeMillis();
LinkedList linkedList=new LinkedList();
for (int i = 0; i < 1000000; i++) {
linkedList.add(i);
}
System.out.println("LinkedList increase "+(System.currentTimeMillis()-s));
The result is ArrayList It's faster than LinkedList
Delete
long s=System.currentTimeMillis();
String str="";
for (int i = 999999; i > -1; i--) {
arrayList.remove(i);
}
System.out.println("ArrayList Deletion at the end "+(System.currentTimeMillis()-s));
s=System.currentTimeMillis();
for (int i = 999999; i > -1; i--) {
linkedList.removeLast();
}
System.out.println("linkedList Deletion at the end "+(System.currentTimeMillis()-s));
The result is ArrayList The speed of is better than LinkedList
It's also necessary to execute more times ArrayList Is faster than LinkedList
边栏推荐
- BOM DOM
- Direct control PTZ PTZ PTZ PTZ camera debugging (c)
- Sparkcontext: error initializing sparkcontext solution
- Anti shake throttle
- 防抖 节流
- In development, why do you find someone who is paid more than you but doesn't write any code?
- Simple use of drools decision table
- Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
- Floyd AcWing 854. Floyd求最短路
- 包管理工具
猜你喜欢
Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
2.6 using recursion and stack - [tower of Hanoi problem]
arcgis js 4.x 地图中加入图片
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
Dijkstra AcWing 850. Dijkstra求最短路 II
哈希表 AcWing 841. 字符串哈希
Drools dynamically add, modify, and delete rules
[ybtoj advanced training guidance] cross the river [BFS]
BOM DOM
包管理工具
随机推荐
传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
Redis bloom filter
浏览器node事件循环
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
线性DP AcWing 899. 编辑距离
Floyd AcWing 854. Floyd求最短路
Go学习笔记—基于Go的进程间通信
Deep Copy Event bus
Oracle从入门到精通(第4版)
Bom Dom
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
Input box assembly of the shutter package
Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
深拷貝 事件總線
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
Calculate the maximum path sum of binary tree
Go learning notes - go based interprocess communication
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
Embedded Software Engineer career planning