日期:2014-05-20 浏览次数:20666 次
int size = 1000000;
ArrayList<Integer> list1 = new ArrayList<Integer>(size);
long start = System.currentTimeMillis();
for(int i=0; i<size; i++)
list1.add(i);
System.out.println(System.currentTimeMillis()-start);
Vector<Integer> list2 = new Vector<Integer>(size);
start = System.currentTimeMillis();
for(int i=0; i<size; i++)
list2.add(i);
System.out.println(System.currentTimeMillis()-start);
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
public class Test {
private static int size = 10000000;
private static Vector<Integer> list2 = new Vector<Integer>(size);
private static ArrayList<Integer> list1 = new ArrayList<Integer>(size);
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>(size);
for(int i=0; i<size; i++)
list.add(i);
long start = System.nanoTime();
for (int i = 0; i < size; i++)
list2.add(list.get(i));
System.out.println(System.nanoTime() - start);
start = System.nanoTime();