日期:2014-05-20 浏览次数:20615 次
long startTime = System.currentTimeMillis();
List<String> arrayList = new ArrayList<String>();
for(int i=0;i<100000;i++){
arrayList.add("a"+i);
}
long endTime = System.currentTimeMillis();
System.out.println("arrayList:"+arrayList.size()+"---"+(endTime - startTime));
long startTime1 = System.currentTimeMillis();
List<String> linkedList = new LinkedList<String>();
for(int i=0;i<100000;i++){
linkedList.add("a"+i);
}
List<String> arrayLinkedList = new ArrayList<String>(linkedList);
long endTime1 = System.currentTimeMillis();
System.out.println("arrayLinkedList:"+arrayLinkedList.size()+"---"+(endTime1 - startTime1));
long startTime1 = System.currentTimeMillis();
List<String> linkedList = new LinkedList<String>();
for(int i=0;i<100000;i++){
linkedList.add("a"+i);
}
long endTime1 = System.currentTimeMillis();
List<String> arrayLinkedList = new ArrayList<String>(linkedList);//这步后移就没问题了,这里进行了一次遍历
System.out.println("arrayLinkedList:"+arrayLinkedList.size()+"---"+(endTime1 - startTime1));
private static void test(int count) {
long startTime = System.currentTimeMillis();
List<String> arrayList = new ArrayList<String>();
for (int i = 0; i < count; i++) {