package com.mangocity.test;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class TestList ...{
public static final int N=50000;
public static List values;
static...{
Integer vals[]=new Integer[N];
Random r=new Random();
for(int i=0,currval=0;i<N;i++)...{
vals=new Integer(currval);
currval+=r.nextInt(100)+1;
}
values=Arrays.asList(vals);
}
static long timeList(List lst)...{
long start=System.currentTimeMillis();
for(int i=0;i<N;i++)...{
int index=Collections.binarySearch(lst, values.get(i));
if(index!=i)
System.out.println("***错误***");
}
return System.currentTimeMillis()-start;
}
public static void main(String args[])...{
System.out.println("ArrayList消耗时间:"+timeList(new ArrayList(values)));
System.out.println("LinkedList消耗时间:"+timeList(new LinkedList(values)));
}
}
这是一篇关于ArrayList和LinkedList的文章中这样写到的,文章很好,文章地址是http://pengcqu.iteye.com/blog/502676有兴趣的童鞋可以去看看。当中public class TestList ...的写法,求解释! |