LinkedList,ArrayList末尾插入谁效率高?

废话不多说,原因不解释,上测试代码:
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 aList = new ArrayList();
		List lList = new LinkedList();
		stopWatch.reset();
		stopWatch.start();
		for(int i=0; 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

你可能感兴趣的:(java基础)