概述
废话不多说,原因不解释。上測试代码:
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<String> aList = new ArrayList<String>();
List<String> lList = new LinkedList<String>();
stopWatch.reset();
stopWatch.start();
for(int i=0; i<num; i++){
aList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
}
LOGGER.info("insert num:{} ArrayList cost:{} ms",num,stopWatch.elapsedTime(TimeUnit.MILLISECONDS));
stopWatch.reset();
stopWatch.start();
for(int i=0; i<num; i++){
lList.add("201411180827 cctv5_800 83 796.03 115.182.51.134 123.125.89.75 in uuid1 5");
}
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<nums.length; i++){
testList(nums[i]);
}
}
}
測试结果:
INFO [main] (JtestMain.java:65) 11:50:47,480 -- insert num:10000 ArrayList cost:2 ms
INFO [main] (JtestMain.java:72) 11:50:47,484 -- insert num:10000 LinkedList cost:1 ms
INFO [main] (JtestMain.java:65) 11:50:47,490 -- insert num:100000 ArrayList cost:5 ms
INFO [main] (JtestMain.java:72) 11:50:47,495 -- insert num:100000 LinkedList cost:5 ms
INFO [main] (JtestMain.java:65) 11:50:47,504 -- insert num:1000000 ArrayList cost:8 ms
INFO [main] (JtestMain.java:72) 11:50:47,515 -- insert num:1000000 LinkedList cost:11 ms
INFO [main] (JtestMain.java:65) 11:50:47,606 -- insert num:10000000 ArrayList cost:89 ms
INFO [main] (JtestMain.java:72) 11:50:49,335 -- insert num:10000000 LinkedList cost:1729 ms
INFO [main] (JtestMain.java:65) 11:50:50,290 -- insert num:100000000 ArrayList cost:954 ms
INFO [main] (JtestMain.java:72) 11:51:14,263 -- insert num:100000000 LinkedList cost:23973 ms
转载于:https://www.cnblogs.com/cxchanpin/p/7105814.html
最后
以上就是怡然萝莉为你收集整理的LinkedList,ArrayList末尾插入谁效率高?的全部内容,希望文章能够帮你解决LinkedList,ArrayList末尾插入谁效率高?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复