最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java中LinkedList和ArrayList性能比对
时间:2014-12-01 编辑:简简单单 来源:一聚教程网
代码如下 | 复制代码 |
package com.letv.cloud.cdn.jtest; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeUnit; import org.slf4j.LoggerFactory; import com.google.common.base.Stopwatch; public class JtestMain { private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger("JtestMain"); private static Stopwatch stopWatch = new Stopwatch(); public static void testList(int num){ List List stopWatch.reset(); stopWatch.start(); for(int i=0; i } LOGGER.info("insert num:{} ArrayList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS)); stopWatch.reset(); stopWatch.start(); for(int i=0; i } LOGGER.info("insert num:{} LinkedList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS)); } public static void main(String[] args) throws InterruptedException, IOException { int[] nums = {10000,10 * 10000,100 * 10000, 1000 * 10000, 10000 * 10000}; for(int i=0; i } } } |
测试结果:
代码如下 | 复制代码 |
INFO [main] (JtestMain.java:65) 11:50:47,480 -- insert num:10000 ArrayList cost:2 ms |
从上面的测试数据我们可以看得到ArrayList 是LinkedList几倍了,数据越大它们的区别就越能体现出来了。
相关文章
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24
- 工厂方法在Spring框架中的运用介绍 10-24