当前位置:网站首页>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
边栏推荐
- CPU指令集介绍
- Lombok common annotations
- Performance tuning project case
- Docker compose configuration mysql, redis, mongodb
- In development, why do you find someone who is paid more than you but doesn't write any code?
- The differences and relationships among port, targetport, nodeport and containerport in kubenetes
- When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
- Go学习笔记—多线程
- CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节
- 深拷贝 事件总线
猜你喜欢
WSL 2 will not be installed yet? It's enough to read this article
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
中国交通标志检测数据集
In development, why do you find someone who is paid more than you but doesn't write any code?
Record the range of data that MySQL update will lock
Floyd AcWing 854. Floyd求最短路
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
趣味 面试题
Use sqoop to export ads layer data to MySQL
What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
随机推荐
Floyd AcWing 854. Floyd求最短路
Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution
Day12 control flow if switch while do While guessing numbers game
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
MySQL与PostgreSQL抓取慢sql的方法
Input a three digit number and output its single digit, ten digit and hundred digit.
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
染色法判定二分图 AcWing 860. 染色法判定二分图
WSL 2 will not be installed yet? It's enough to read this article
[C language] convert decimal numbers to binary numbers
Docker compose configuration mysql, redis, mongodb
China traffic sign detection data set
BOM DOM
Fluent fluent library encapsulation
drools执行指定的规则
"As a junior college student, I found out how difficult it is to counter attack after graduation."
Shutter encapsulated button
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
Docker-compose配置Mysql,Redis,MongoDB