import java.util.ArrayList;
import java.util.LinkedList;
public class ArrayListVSLinkedList {
public static void main(String[] args) {
long startTimeA = System.currentTimeMillis();
for(int i=0;i<1000;i++){
ArrayList al =new ArrayList();
al.add(i);
}
long endtimeA = System.currentTimeMillis();
System.out.println("ArrayList Time is "+(endtimeA-startTimeA)+"ms");
long startTimeL = System.currentTimeMillis();
for (int i=1;i<1000;i++){
LinkedList ll = new LinkedList();
ll.add(i);
}
long endtimeL = System.currentTimeMillis();
System.out.println("LiknedList Time is "+(endtimeL-startTimeL) +"ms");
}
}
Note: Red color denoted by ArrayList, Green color denotes by LinkedList.
No comments:
Post a Comment