LinkedListWrongDemo
public class LinkedListWrongDemo { public static void main(String[] args) { int size = 2000000; List<String> list = new LinkedList<String>(); for(int i = 0;i<size;i++) { list.add("Just some test data"); } long startTime = System.currentTimeMillis(); for(int i = 0;i<size;i++) { list.get(i); if(i%10000 ==0) { System.out.println("query 10000 elements spend: "+ (System.currentTimeMillis()-startTime)); startTime = System.currentTimeMillis(); } } } }
程序输出:
query 10000 elements spend: 0
query 10000 elements spend: 78
query 10000 elements spend: 223
query 10000 elements spend: 345
query 10000 elements spend: 610
query 10000 elements spend: 610
query 10000 elements spend: 740
query 10000 elements spend: 860
query 10000 elements spend: 1020
query 10000 elements spend: 1198
query 10000 elements spend: 1420
query 10000 elements spend: 1640
query 10000 elements spend: 1900
query 10000 elements spend: 2405
query 10000 elements spend: 2500
query 10000 elements spend: 2740
query 10000 elements spend: 3000
query 10000 elements spend: 3390
query 10000 elements spend: 3560
query 10000 elements spend: 3940
query 10000 elements spend: 4248
........