My lenovo Y480N IFI

CPU: I53210m
Mem:  8GB
HDD: 1T

vector,arraylist,linkedlist add 1000,000 elements
spent below time(ms):
vector time=448
array list time=293
linked list time=152

It's so strong than 10 years ago  
Codes:
public class LinkedListCompare {
	private final int x=1000000;
	
	public static void main(String[] args){
		LinkedListCompare llc=new LinkedListCompare();
		System.out.println("vector time="+llc.vectorTime());
		
		System.out.println("array list time="+llc.arrayListTime());
		
		System.out.println("linked list time="+llc.linkedListTime());
	}
	
	public long vectorTime(){
		long t1=System.currentTimeMillis();
		Vector v=new Vector();
		for(int i=0;i<x;i++){
			v.add("elements"+i);
		}
		long t2=System.currentTimeMillis();
		return (t2-t1);
	}
	
	public long arrayListTime(){
		long t1=System.currentTimeMillis();
		List list=new ArrayList();
		for(int i=0;i<x;i++){
		list.add("elements"+i);
		}
		long t2=System.currentTimeMillis();
		return (t2-t1);
	}

	public long linkedListTime(){
		long t1=System.currentTimeMillis();
		List list=new LinkedList();
		for(int i=0;i<x;i++){
		list.add("elements"+i);
		}
		long t2=System.currentTimeMillis();
		return (t2-t1);
	}
}



你可能感兴趣的:(if)